package com.fy56.platform.goodsTracking.api.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.JSONPObject;
import com.dexcoder.dal.JdbcDao;
import com.fy56.model.ResultModel;
import com.fy56.platform.goodsTracking.api.GoodsTrackApi;
import com.fy56.platform.goodsTracking.commons.DateUtil;
import com.fy56.platform.goodsTracking.commons.unit.SystemConstants;
import com.fy56.platform.goodsTracking.model.*;
import com.fy56.platform.goodsTracking.quartz.JrptUpload;
import com.fy56.platform.goodsTracking.quartz.OrderUtil;
import com.fy56.platform.goodsTracking.service.GoodsTrackedSetingPublicService;
import com.fy56.platform.goodsTracking.service.JrptService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

/**
 * Created by XTK on 2016-08-18.
 */
@Repository
public class GoodsTrackApiImpl implements GoodsTrackApi {
    @Autowired
    JdbcDao jdbcDao;

    @Autowired
    JdbcDao jdbcDao_GoodsTracked;

    @Autowired
    JrptUpload jrptExecutor;


    @Autowired
    JrptService jrptService;

    @Autowired
    GoodsTrackedSetingPublicService goodsTrackedSetingPublicService;

    private static final Logger log = LoggerFactory.getLogger(GoodsTrackApiImpl.class);

    @Override
    public void insert_extract(String dataSource, String databasename, String wxpublicnumber, String appid) {
        if (wxpublicnumber == null) {
            wxpublicnumber = "";
        }
        if (appid == null) {
            appid = "";
        }
        //货物跟踪数据
        Long begin;
        Long end;
        String datetime = DateUtil.Now();

        int numTmp = 0;
        String sqlArray0 = "";
        int i = 1;

        List<GoodsTrack> listByDelete = new ArrayList<GoodsTrack>();
        Jrpt jrpt;
        String upload;
        begin = System.currentTimeMillis();
        //更新金融平台代码
        List<GoodstrackedSeting> setingList = jdbcDao.queryListForSql("select Organizationcode, Info=isnull(stuff((select ','+'\"'+TYPE+'\"'+':'+'\"'+Info+'\"'  from GoodsTracked_Seting t \n" +
                "where  Type like '%JRPT%' and Organizationcode=GoodsTracked_Seting.Organizationcode for xml path('')), 1, 1, '') \n" +
                ",'空') from GoodsTracked_Seting \n" +
                "group by Organizationcode ", GoodstrackedSeting.class);

        for (GoodstrackedSeting seting : setingList) {
            jrpt = new Jrpt();
            if (!seting.getInfo().equals("") && !seting.getInfo().equals("空")) {
                try {
                    String info = "{" + seting.getInfo() + "}";
                    //log.info("DataSource:" + dataSource + ";Databasename:" + databasename + ";更新金融代码:" + info);
                    JSONObject jb = JSON.parseObject(info);
                    if (!jb.get("JRPT_User").equals("")) {
                        jrpt.setOrganizationcode(seting.getOrganizationcode());
                        jrpt.setJrptuser(String.valueOf(jb.get("JRPT_User")));
                        jrpt.setJrptpass(String.valueOf(jb.get("JRPT_Pass")));
                        upload = String.valueOf(jb.get("JRPT_Upload"));
                        // jrptService.delete(jrpt.getOrganizationcode());
                        if (upload.equals("1"))
                            jrptService.save(jrpt);
                    }
                } catch (Exception e) {
                    log.error("DataSource:" + dataSource + ";Databasename:" + databasename + ";更新金融平台代码失败:" + e.getMessage());
                }
            }
        }
        end = System.currentTimeMillis();
        log.info("Databasename:" + databasename +"更新JRPT消耗" + (end - begin) + "豪秒。");
        String insertSql;
        String seleclSql;
        //同步货运单数据
        ConsignmentBillMaster consignmentBillMaster = new ConsignmentBillMaster();
        List<ConsignmentBillMaster> listByConsignmentBillMasterDelete = new ArrayList<ConsignmentBillMaster>();

        String timeSql="and SysTime<='"+datetime+"'";
        begin = System.currentTimeMillis();
        insertSql = "insert into GoodsTracked_Record_Top_Public( " +
                "fuelcost,headquartersname,CreateOperator,CreateTime,headquarterphone,databasename,consignorCompanySende,consigneeCompanySenderCode,createType"+
                ",ConsignmentLongitude,ConsignmentLatitude,ArrivalLongitude,ArrivalLatitude," +
                "SendLongitude,SendLatitude,PickAddress,PlatformNumber,ReceiveLongitude,ReceiveLatitude," +
                "Headquarterscode,headquarterspassword,arrivalcode,arrivalpassword,consignmentcode ,consignmentpassword," +
                "  OrganizationCode,ConsignmentBillMasterId,ConsignmentBillNumber,GoodsNumber,ManualNumber,ConsignmentBillDate,PlaceOfLoading,SendCompany,ReceiveCompany,UnloadPlace,ConsignorCompanyCode,ConsignorCompany,Consignor,ConsignorMobileTelephone,ConsignorTelephone,ConsignorAddress,ConsigneeCompanyCode,ConsigneeCompany, Consignee,ConsigneeMobileTelephone" +
                "  ,ConsigneeTelephone, ConsigneeAddress,Consignoridcard,Consigneeidcard,OneCardCode,BankName,AccountHolder,Account,PaymentMethod,GoodsPickupMethod,ConsignmentBillRemark,GoodsName, GoodsPack,IsReceipt,ReceiptNumber,ReceiptCount,ReceiptRemark,TotalNumberOfPackages," +
                " TotalWeight,ArrivalAllPayCost,InsuranceAmount,InsuranceCost, TotalVolume," +
                "TransferCost,SendCost,PickupCost,PackCost,OtherCost,TotalTransportCost, CollectionGoodsValue,AdvanceGoodsValue,AdvanceTransportCost,DataType,SysTime)";
        seleclSql = " select '" +
                "'''+Isnull(convert(varchar(20),convert(FLOAT,t.fuelcost)), '0')+'''," +
                "'''+Isnull(z.CompanyName, '')+'''," +
                "'''+Isnull(t.CreateOperator, '')+'''," +
                "'''+Isnull(CONVERT(varchar(100), t.CreateTime, 20), '')+'''," +

                "'''+Isnull(z.CompanyPhoneNumber, '')+'''," +
                "''' +'"+databasename+"'+'''," +
                "'''+Isnull(c.FyCloudCode, z.LoginkCode)+'''," +
                "'''+Isnull(dh.FyCloudCode, '')+'''," +
                "' +Isnull(convert(varchar(20),convert(decimal(18,0),createtype)), '0')+ '," +

                "'''+Isnull(c.Longitude, Isnull(z.Longitude,''))+'''," +
                "'''+Isnull(c.Latitude, Isnull(z.Latitude,''))+'''," +
                "'''+Isnull(dh.Longitude, '')+'''," +
                "'''+Isnull(dh.Latitude, '')+'''," +

                "'''+Isnull(CONVERT(varchar(200),t.SendLongitude), '')+'''," +
                "'''+Isnull(CONVERT(varchar(200),t.SendLatitude), '')+'''," +
                "'''+Isnull(t.PickAddress, '')+'''," +
                "'''+Isnull(t.PlatformNumber, '')+'''," +
                "'''+Isnull(CONVERT(varchar(200),t.ReceiveLongitude), '')+'''," +
                "'''+Isnull(CONVERT(varchar(200),t.ReceiveLatitude), '')+'''," +

                "'''+case when isnull(bf.FyCloudCode,'')='' then z.FyCloudCode else bf.FyCloudCode end+'''," +
                "'''+case when isnull(bf.FyCloudPassword,'')='' then z.FyCloudPassword else bf.FyCloudPassword end+'''," +
                "'''+Isnull(dh.FyCloudCode, '')+'''," +
                "'''+Isnull(dh.FyCloudPassword, '')+'''," +
                "'''+Isnull(c.FyCloudCode, Isnull(z.LoginkCode,''))+'''," +
                "'''+Isnull(c.FyCloudPassword,  Isnull(z.LoginkPassword,''))+''','''" +
                "+CASE WHEN isnull(bf.GoodsTrackedOrg,'')<>'' THEN bf.GoodsTrackedOrg ELSE Isnull(t.OrganizationCode, '') end+''','''" +
                "+CASE WHEN bf.GoodsTrackedOrg=bf.FromOrganizationCode THEN bf.FromConsignmentBillMasterId WHEN bf.GoodsTrackedOrg=bf.ToOrganizationCode THEN bf.ToConsignmentBillMasterId ELSE t.ConsignmentBillMasterId end " +
                "+''','''+Isnull(t.ConsignmentBillNumber, '')+''','''+Isnull(GoodsNumber, '')+''','''+Isnull(ManualNumber, '')+''','''+Isnull(CONVERT(varchar(100), ConsignmentBillDate, 20), '')+''','''+Isnull(PlaceOfLoading, '')+''','''+Isnull(SendCompany, '')+''','''" +
                " +Isnull(ReceiveCompany, '')+''','''+Isnull(UnloadPlace, '')+''','''+Isnull(ConsignorCompanyCode, '')+''','''+Isnull(ConsignorCompany, '')+''','''+Isnull(Consignor, '')+''','''+Isnull(ConsignorMobileTelephone, '')+''','''+Isnull(ConsignorTelephone, '')+''','''+Isnull(ConsignorAddress, '')+''','''" +
                " +Isnull(ConsigneeCompanyCode, '')+''','''+Isnull(ConsigneeCompany, '')+''','''+Isnull(Consignee, '')+''','''+Isnull(ConsigneeMobileTelephone, '')+''','''+Isnull(ConsigneeTelephone, '')+''','''+Isnull(ConsigneeAddress, '')+''','''+isnull(Consignoridcard,'')+''','''+isnull(Consigneeidcard,'')+''','''+Isnull(OneCardCode, '')+''','''+Isnull(BankName, '')+''','''" +
                " +Isnull(AccountHolder,'')+''','''+Isnull(Account,'')+''','''+Isnull(PaymentMethod,'')+''','''+Isnull(GoodsPickupMethod,'')+''','''+Isnull(ConsignmentBillRemark,'')+''','''+Isnull(GoodsName,'')+''','''+ Isnull(GoodsPack,'')+''','''+Isnull(IsReceipt,'')+''','''+Isnull(ReceiptNumber,'')+''','" +
                " +Isnull(convert(varchar(20),convert(decimal(18,0),ReceiptCount)), '0')+',''' +Isnull(ReceiptRemark,'')+''','+Isnull(convert(varchar(20),convert(decimal(18,0),TotalNumberOfPackages)),'0')+','" +
                " +Isnull(convert(varchar(20),convert(FLOAT,TotalWeight)), '0')+',' " +
                " +Isnull(convert(varchar(20),convert(FLOAT,ArrivalAllPayCost)), '0')+',' " +
                " +Isnull(convert(varchar(20),convert(DECIMAL,InsuranceAmount)), '0')+',' " +
                " +Isnull(convert(varchar(20),convert(FLOAT,InsuranceCost)), '0')+',' " +
                " +Isnull(convert(varchar(20),convert(FLOAT,TotalVolume)), '0')+','" +

                " +Isnull(convert(varchar(20),convert(FLOAT,TransferCost)), '0')+','" +
                " +Isnull(convert(varchar(20),convert(FLOAT,SendCost)), '0')+','" +
                " +Isnull(convert(varchar(20),convert(FLOAT,PickupCost)), '0')+','" +
                " +Isnull(convert(varchar(20),convert(FLOAT,PackCost)), '0')+','" +
                " +Isnull(convert(varchar(20),convert(FLOAT,OtherCost)), '0')+','" +

                " +Isnull(convert(varchar(20),convert(FLOAT,TotalTransportCost)), '0')+',' + Isnull(convert(varchar(20),convert(FLOAT,CollectionGoodsValue)), '0') +',' +Isnull(convert(varchar(20),convert(decimal(18,0),AdvanceGoodsValue)), '0')+','" +
                " +Isnull(convert(varchar(20),convert(FLOAT,AdvanceTransportCost)), '0')+','+Isnull(convert(varchar(20),convert(decimal(18,0),DataType)), '0')+','''+Isnull(CONVERT(varchar(100), SysTime, 20), '') +'''' sqltext " +
                ",CONVERT(varchar(100), SysTime, 20) systime,convert(varchar(20),convert(decimal(18,0),DataType)) datatype" +
                " ,t.organizationcode,CASE WHEN bf.GoodsTrackedOrg=bf.FromOrganizationCode THEN bf.FromConsignmentBillMasterId WHEN bf.GoodsTrackedOrg=bf.ToOrganizationCode THEN bf.ToConsignmentBillMasterId ELSE t.ConsignmentBillMasterId end as consignmentbillmasterid " +

                " from GoodsTracked_Record_Top t WITH(NOLOCK) " +
                " left join Sys_Company c WITH(NOLOCK) on t.OrganizationCode=c.OrganizationCode and t.SendCompany=c.CompanyName " +
                "    left join Sys_Company dh WITH(NOLOCK) on t.OrganizationCode=dh.OrganizationCode and t.ReceiveCompany=dh.CompanyName " +
                "    left join Sys_Company z WITH(NOLOCK) on t.OrganizationCode=z.OrganizationCode and z.CompanyType='总公司'"
                +" LEFT JOIN CooCompanyRelationInfo bf WITH(NOLOCK) on t.OrganizationCode=bf.OrganizationCode AND t.ConsignmentBillNumber=bf.ConsignmentBillNumber "
                + "  where 1=1 and t.SysTime<='"+datetime+"'";
        String testSql=" and (t.datatype!='100' or t.datatype is null) order by t.SysTime asc ";
        seleclSql=seleclSql+testSql;
//        + "  where t.SysTime<='" + datetime + "'";

        List<ConsignmentBillMaster> listByConsignmentBillMaster = null;

        try{
            listByConsignmentBillMaster = jdbcDao.queryListForSql(seleclSql, ConsignmentBillMaster.class);
        }catch (Exception e){
            log.error("DataSource:" + dataSource + ";Databasename:" + databasename +"货运单 error",e);
        }

        end = System.currentTimeMillis();
        log.info("DataSource:" + dataSource + ";Databasename:" + databasename + ";货运单数据：" + listByConsignmentBillMaster.size() + ";消耗" + (end - begin) + "豪秒。");
        //log.info("查询sql："+seleclSql);

        numTmp = 0;
        sqlArray0 = "";
        i = 1;
        begin = System.currentTimeMillis();
        String ConsignmentBillMasterIdStr = "";
        for (ConsignmentBillMaster s : listByConsignmentBillMaster) {

            if (ConsignmentBillMasterIdStr==null||ConsignmentBillMasterIdStr.length()==0){
                ConsignmentBillMasterIdStr="'"+s.getConsignmentbillmasterid()+"'";
            } else {
                ConsignmentBillMasterIdStr=ConsignmentBillMasterIdStr+","+"'"+s.getConsignmentbillmasterid()+"'";
            }

            if("ccchengquan".equals(s.getOrganizationcode())){
                log.error("ccchengquan:"+s.getSqltext());
            }
            if (s.getSqltext()==null||"null".equals(s.getSqltext())||"NULL".equals(s.getSqltext())||s.getSqltext().length()==0){
                log.error("订单查询异常null error id:"+s.getConsignmentbillmasterid());
            }else{

            }
            try {
                if (s.getDatatype().equals("0")) {
                    try {
                        jdbcDao_GoodsTracked.updateForSql(insertSql + " values " + "(" + s.getSqltext() + ")");
                    } catch (Exception e) {
                        log.info("货运单新增插入sql的值" + insertSql + " values " + "(" + s.getSqltext() + ")");
                        log.info("货运单新增插入异常ConsignmentBillMaster对象的值" + JSON.toJSONString(s) +"");
                        log.error("DataSource:" + dataSource + ";Databasename:" + databasename + ";货运单插入异常：" + s.getConsignmentbillmasterid() );
                        e.printStackTrace();
                    }
                } else if (s.getDatatype().equals("1")) {

                    //如果是修改  需要把原记录的唯一id取出  然后插入一条状态是修改的新记录 把原记录的唯一id更新到新记录上 然后把原记录删除
                    List<GoodstrackedRecordTopPublicF6> list=jdbcDao_GoodsTracked.queryListForSql("select * from Order_temp where   ConsignmentBillMasterId='" + s.getConsignmentbillmasterid() + "'"  ,GoodstrackedRecordTopPublicF6.class);
                    jdbcDao_GoodsTracked.updateForSql("delete  from GoodsTracked_Record_Top_Public where   ConsignmentBillMasterId='" + s.getConsignmentbillmasterid() + "'");
                    try {
                        jdbcDao_GoodsTracked.updateForSql(insertSql + " values " + "(" + s.getSqltext() + ")");
                    } catch (Exception e) {
                        log.info("货运单修改插入sql的值" + insertSql + " values " + "(" + s.getSqltext() + ")");
                        log.info("货运单修改插入异常ConsignmentBillMaster对象的值" + JSON.toJSONString(s) +"");
                        log.error("DataSource:" + dataSource + ";Databasename:" + databasename + ";货运单插入异常：" + s.getConsignmentbillmasterid() );
                        e.printStackTrace();
                    }
                        if(list!=null && list.size()>0&&list.get(0).getTraceplatformid()!=null&&list.get(0).getTraceplatformid().length()!=0&&!("null").equals(list.get(0).getTraceplatformid())){
                            jdbcDao_GoodsTracked.updateForSql("update GoodsTracked_Record_Top_Public set TracePlatformId = '"+ list.get(0).getTraceplatformid()+"' where  ConsignmentBillMasterId='" + s.getConsignmentbillmasterid() + "'");
                        }else{
                            //由于新添加的订单还没有上传，修改的数据就过来了，所以直接按添加推送
                            jdbcDao_GoodsTracked.updateForSql("update GoodsTracked_Record_Top_Public set datatype=0 where  ConsignmentBillMasterId='" + s.getConsignmentbillmasterid() + "'");
                        }


//                    consignmentBillMaster.setOrganizationcode(s.getOrganizationcode());
//                    consignmentBillMaster.setConsignmentbillmasterid(s.getConsignmentbillmasterid());
//                    consignmentBillMaster.setSystime(s.getSystime());
//                    listByConsignmentBillMasterDelete.add(consignmentBillMaster);
                } else if (s.getDatatype().equals("2")) {
                    List<GoodstrackedRecordTopPublicF6> list=jdbcDao_GoodsTracked.queryListForSql("select * from Order_temp where   ConsignmentBillMasterId='" + s.getConsignmentbillmasterid() + "'"  ,GoodstrackedRecordTopPublicF6.class);
                    if(list!=null&&list.size()>0&&list.get(0).getTraceplatformid()!=null&&list.get(0).getTraceplatformid().length()!=0&&!("null").equals(list.get(0).getTraceplatformid())){
                        //如果是删除  需要把原记录的状态更新为删除   然后不需要删除
                        jdbcDao_GoodsTracked.updateForSql("update GoodsTracked_Record_Top_Public set Systime='"+datetime+"',DataType = '2',uploadFlag='' where  ConsignmentBillMasterId='" + s.getConsignmentbillmasterid() + "'");
                    }else{
                        //由于新添加的订单还没有上传，删除的数据就过来了，所以直接按添加推送
                        log.error("删除订单id:"+s.getConsignmentbillmasterid());
                        jdbcDao_GoodsTracked.updateForSql("delete from  GoodsTracked_Record_Top_Public   where  ConsignmentBillMasterId='" + s.getConsignmentbillmasterid() + "'");
                    }
                }else{
                    log.error("订单查询异常Datatype error id:"+s.getConsignmentbillmasterid());
                }
            } catch (Exception e) {
                log.info(insertSql + " values " + "(" + s.getSqltext() + ")" + "error9:", e);
                e.printStackTrace();
            }
        }

        end = System.currentTimeMillis();
        try {
            if(ConsignmentBillMasterIdStr!=null&&ConsignmentBillMasterIdStr.length()!=0){
                String billMasterIdS []=ConsignmentBillMasterIdStr.split(",");
                for(int c=0;c<billMasterIdS.length;c++){
                    String id =billMasterIdS[c];
                    if(id!=null&&id.length()!=0){
                        String f6sql =" delete from GoodsTracked_Record_Top  where ConsignmentBillMasterId =" + id + " " +timeSql;
                        log.info("editF6:" + f6sql);
                        jdbcDao.updateForSql(f6sql);
                    }
                }
            }
            SimpleDateFormat formatter  = new SimpleDateFormat("yyyy-MM-dd");
            String ctime = formatter.format(new Date())+" 00:00:00";
            String f6sql =" delete from GoodsTracked_Record_Top  where " + " SysTime<'"+ctime+"'";
            log.info("deleteAndTime:" + f6sql);
            jdbcDao.updateForSql(f6sql);
        } catch (Exception e) {
            e.printStackTrace();
        }
        log.info("DataSource:" + dataSource + ";Databasename:" + databasename + ";保存货运单数据消耗" + (end - begin) + "豪秒。");

//        //货物跟踪数据
//        begin = System.currentTimeMillis();
//        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//        String createTime=sdf.format(new Date());
//        insertSql = "insert into GoodsTracked_Record_Public(OrganizationCode, ConsignmentBillMasterId,createTime,TypeNum,TypeName, Info, SysTime,CreateOperator, CreateCompanyName,DataType,OtherNumber" +
//                ",DriverCode,DriverName,CarLicense," +
//                "DeliveryDate,ReceivePerson,DeliveryCompany,ArrivalQueryPhone,TransferCompanySendPhone,TransferCompanyReceive,"+
//
//                "Longitude,Latitude)";
//        seleclSql = "select ''''+ mb.OrganizationCode+''','''+mb.ConsignmentBillMasterId+'''" +
//                ",''' +'"+createTime+"'+'''" +
//                ",'+convert(varchar,(case when mb.TypeNum='' then 99 else mb.typenum end))+','''+mb.TypeName+''','''+mb.Info+''','''+ CONVERT(varchar(100), mb.SysTime, 20)+''','''+mb.CreateOperator+''','''+mb.CreateCompanyName+''','+convert(varchar(20),convert(decimal(18,0),mb.DataType))+','''+mb.OtherNumber+'''" +
//                ",'''+ mb.DriverCode+'''" +
//                ",'''+ mb.DriverName+'''" +
//                ",'''+ mb.CarLicense+'''" +
//
//                ",'''+ Isnull(CONVERT(varchar(100), DeliveryDate, 23),'')+'''" +
//                ",'''+ Isnull(ReceivePerson,'')+'''" +
//                ",'''+ Isnull(DeliveryCompany,'')+'''" +
//                ",'''+ Isnull(ArrivalQueryPhone,'')+'''" +
//                ",'''+ Isnull(TransferCompanySendPhone,'')+'''" +
//                ",'''+ Isnull(TransferCompanyReceive,'')+'''" +
//
//
//                ",'''+ cast(mb.Longitude as varchar)+'''" +
//                ",'''+  cast(mb.Latitude as varchar)+'''" +
//                " ' sqltext,CONVERT(varchar(100), mb.SysTime, 20) systime,convert(varchar(20),convert(decimal(18,0),mb.DataType)) datatype,mb.organizationcode,mb.consignmentbillmasterid,mb.typenum " +
//                " from GoodsTracked_Record mb "+
//                " LEFT JOIN DeliveryBill db ON mb.ConsignmentBillMasterId=db.ConsignmentBillMasterId  " +
//                " LEFT JOIN Sys_Company b ON db.DeliveryCompany=b.CompanyName AND db.OrganizationCode=b.OrganizationCode"+
//
//                "  where mb.SysTime<='" + datetime + "'";
//        List<GoodsTrack> list=null;
//        try{
//            list = jdbcDao.queryListForSql(seleclSql, GoodsTrack.class);
//        }catch (Exception e){
//            log.error("DataSource:" + dataSource + ";Databasename:" + databasename +"货物跟踪 error",e);
//        }
//
//        end = System.currentTimeMillis();
//        log.info("DataSource:" + dataSource + ";Databasename:" + databasename + ";货物跟踪数据：" + list.size() + ";消耗" + (end - begin) + "豪秒。");
//        //log.info("货物跟踪查询sql："+seleclSql);
//        GoodsTrack goodsTrack = new GoodsTrack();
//        begin = System.currentTimeMillis();
//        sqlArray0 = "";
//        for (GoodsTrack s : list) {
//            try {
//                if (s.getDatatype().equals("0") || s.getDatatype().equals("1")) {
//                    try {
//                        jdbcDao_GoodsTracked.updateForSql(insertSql + " values (" + s.getSqltext() + ")");
//                    } catch (Exception e) {
//                        e.printStackTrace();
//                    }
//
//                    if (s.getDatatype().equals("1")) {
//                        goodsTrack = new GoodsTrack();
//                        goodsTrack.setOrganizationcode(s.getOrganizationcode());
//                        goodsTrack.setConsignmentbillmasterid(s.getConsignmentbillmasterid());
//                        goodsTrack.setTypenum(s.getTypenum());
//                        goodsTrack.setDatatype(s.getDatatype());
//                        goodsTrack.setSystime(s.getSystime());
//                        listByDelete.add(goodsTrack);
//                    }
//
//                } else if (s.getDatatype().equals("2")) {
//                    goodsTrack.setOrganizationcode(s.getOrganizationcode());
//                    goodsTrack.setConsignmentbillmasterid(s.getConsignmentbillmasterid());
//                    goodsTrack.setDatatype(s.getDatatype());
//                    goodsTrack.setTypenum(s.getTypenum());
//                    goodsTrack.setSystime(s.getSystime());
//                    listByDelete.add(goodsTrack);
//                }
//            } catch (Exception e) {
//                e.printStackTrace();
//            }
//        }
///*        if (sqlArray0.length() > 10) {
//            jdbcDao_GoodsTracked.updateForSql(insertSql + " values " + sqlArray0.substring(1, sqlArray0.length()));
//        }*/
//        //处理修改、删除记录
//        try {
//            for (GoodsTrack s : listByDelete) {
//                if(s.getTypenum()==null||s.getTypenum().length()==0){
//                    jdbcDao_GoodsTracked.updateForSql("delete from GoodsTracked_Record_Public where " +
//                            "OrganizationCode='" + s.getOrganizationcode() + "'"
//                            + " and OtherNumber='" + s.getConsignmentbillmasterid() + "'"
//                            + " and TypeNum is null"
//                            + " and sysTime<'" + s.getSystime() + "'");
//                }else{
//                    jdbcDao_GoodsTracked.updateForSql("delete from GoodsTracked_Record_Public where " +
//                            "OrganizationCode='" + s.getOrganizationcode() + "'"
//                            + " and OtherNumber='" + s.getConsignmentbillmasterid() + "'"
//                            + " and TypeNum=" + s.getTypenum()
//                            + " and sysTime<'" + s.getSystime() + "'");
//                }
//
//            }
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//        end = System.currentTimeMillis();
//        try {
//            //不应该注释
//            jdbcDao.updateForSql("delete from GoodsTracked_Record where  sysTime<='" + datetime + "'");
//            log.info("delete from GoodsTracked_Record where  sysTime<='" + datetime + "'");
//        } catch (Exception e) {
//            log.error("删除失败:" + e.getMessage());
//            e.printStackTrace();
//        }
//        log.info("DataSource:" + dataSource + ";Databasename:" + databasename + ";保存货物跟踪数据消耗" + (end - begin) + "豪秒。");
    }





    @Override
    public void insert_goods(String dataSource, String databasename, String wxpublicnumber, String appid) {

        String datetime = DateUtil.Now();

        int numTmp = 0;
        String sqlArray0 = "";
        int i = 1;

        List<GoodsTrack> listByDelete = new ArrayList<GoodsTrack>();

        //货物跟踪数据
        Long begin;
        String insertSql;
        String seleclSql;
        Long end;
        //货物跟踪数据
        begin = System.currentTimeMillis();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String createTime=sdf.format(new Date());
        insertSql = "insert into GoodsTracked_Record_Public(OrganizationCode, ConsignmentBillMasterId,createTime,TypeNum,TypeName, Info, SysTime,CreateOperator, CreateCompanyName,DataType,OtherNumber" +
                ",DriverCode,DriverName,CarLicense," +
                "DeliveryDate,ReceivePerson,DeliveryCompany,ArrivalQueryPhone,TransferCompanySendPhone,TransferCompanyReceive,"+

                "Longitude,Latitude)";
        seleclSql = "select ''''+ mb.OrganizationCode+''','''+mb.ConsignmentBillMasterId+'''" +
                ",''' +'"+createTime+"'+'''" +
                ",'+convert(varchar,(case when mb.TypeNum='' then 99 else mb.typenum end))+','''+mb.TypeName+''','''+mb.Info+''','''+ CONVERT(varchar(100), mb.SysTime, 20)+''','''+mb.CreateOperator+''','''+" +
                "mb.CreateCompanyName+''','+convert(varchar(20),convert(decimal(18,0),mb.DataType))+','''+mb.OtherNumber+'''" +
                ",'''+ mb.DriverCode+'''" +
                ",'''+ mb.DriverName+'''" +
                ",'''+ mb.CarLicense+'''" +

                ",'''+ Isnull(CONVERT(varchar(100), DeliveryDate, 23),'')+'''" +
                ",'''+ Isnull(ReceivePerson,'')+'''" +
                ",'''+ Isnull(DeliveryCompany,'')+'''" +
                ",'''+ Isnull(ArrivalQueryPhone,'')+'''" +
                ",'''+ Isnull(TransferCompanySendPhone,'')+'''" +
                ",'''+ Isnull(TransferCompanyReceive,'')+'''" +


                ",'''+ cast(mb.Longitude as varchar)+'''" +
                ",'''+  cast(mb.Latitude as varchar)+'''" +
                " ' sqltext,CONVERT(varchar(100), mb.SysTime, 20) systime,convert(varchar(20),convert(decimal(18,0),mb.DataType)) datatype,mb.organizationcode,mb.consignmentbillmasterid,mb.typenum " +
                " from GoodsTracked_Record mb "+
                " LEFT JOIN DeliveryBill db ON mb.ConsignmentBillMasterId=db.ConsignmentBillMasterId  " +
                " LEFT JOIN Sys_Company b ON db.DeliveryCompany=b.CompanyName AND db.OrganizationCode=b.OrganizationCode"+

                "  where mb.SysTime<='" + datetime + "'";

//        createTime，DeliveryCompany，DeliveryDate，ArrivalQueryPhone，ReceivePerson，TransferCompanySendPhone，TransferCompanyReceive
        seleclSql =" select mb.Recordid Recordid, CONVERT(varchar(100), mb.SysTime, 20) systime,mb.typenum,mb.TypeName,mb.Info,mb.CreateOperator,mb.CreateCompanyName,mb.DataType," +
                "mb.OtherNumber,mb.OtherNumber, " +
                "mb.OrganizationCode," +
                " CASE WHEN isnull(bf.GTConsignmentBillMasterId,'')<>'' then bf.GTConsignmentBillMasterId WHEN isnull(bt.GTConsignmentBillMasterId,'')<>'' THEN  bt.GTConsignmentBillMasterId  ELSE mb.ConsignmentBillMasterId END  AS ConsignmentBillMasterId," +
                "Isnull(CONVERT(varchar(100), DeliveryDate, 23),'') as DeliveryDate," +
                " Isnull(ReceivePerson,'') ReceivePerson," +
                " Isnull(DeliveryCompany,'') DeliveryCompany," +
                " Isnull(ArrivalQueryPhone,'') ArrivalQueryPhone, " +
                " Isnull(TransferCompanySendPhone,'') TransferCompanySendPhone, " +
                " Isnull(TransferCompanyReceive,'') TransferCompanyReceive " +

                " from GoodsTracked_Record mb WITH(NOLOCK) " +
                " LEFT JOIN DeliveryBill db WITH(NOLOCK) ON mb.ConsignmentBillMasterId=db.ConsignmentBillMasterId " +
                " LEFT JOIN Sys_Company b WITH(NOLOCK) ON db.DeliveryCompany=b.CompanyName AND db.OrganizationCode=b.OrganizationCode  " +
                " LEFT JOIN CooCompanyRelationInfo bf WITH(NOLOCK) ON mb.ConsignmentBillMasterId=bf.FromConsignmentBillMasterId " +
                " LEFT JOIN CooCompanyRelationInfo bt WITH(NOLOCK) ON mb.ConsignmentBillMasterId=bt.ToConsignmentBillMasterId "+
                " where 1=1";
        List<GoodstrackedRecordPublic> list=null;
        String f6Id="";
        try{
            list = jdbcDao.queryListForSql(seleclSql, GoodstrackedRecordPublic.class);
        }catch (Exception e){
            log.error("DataSource:" + dataSource + ";Databasename:" + databasename +"货物跟踪 error",e);
        }

        end = System.currentTimeMillis();
        log.info("DataSource:" + dataSource + ";Databasename:" + databasename + ";货物跟踪查询：" + list.size() + ";消耗" + (end - begin) + "豪秒。");

        //log.info("货物跟踪查询sql："+seleclSql);


        begin = System.currentTimeMillis();
        GoodsTrack goodsTrack = new GoodsTrack();
        begin = System.currentTimeMillis();
        for (GoodstrackedRecordPublic s : list) {
            if (f6Id==null||f6Id.length()==0){
                f6Id="'"+s.getRecordid()+"'";
            } else {
                f6Id=f6Id+","+"'"+s.getRecordid()+"'";
            }
            if (s.getTypenum()==null||s.getTypenum()==""){
                s.setTypenum("99");
            }
            if (s.getLongitude()==null){
               s.setLongitude(new BigDecimal("0.000"));
            }
            if (s.getLatitude()==null){
                s.setLatitude(new BigDecimal("0.000"));
            }
            String info =s.getInfo();
            if (info!=null&&info.length()!=0){
                info=info.replace("'","");
            }
            String sqlInsert="insert into GoodsTracked_Record_Public(OrganizationCode, ConsignmentBillMasterId,createTime,TypeNum,TypeName, Info, SysTime,CreateOperator, CreateCompanyName,DataType,OtherNumber" +
                    ",DriverCode,DriverName,CarLicense," +
                    "DeliveryDate,ReceivePerson,DeliveryCompany,ArrivalQueryPhone,TransferCompanySendPhone,TransferCompanyReceive,"+

                    "Longitude,Latitude) values("+
                    "'"+s.getOrganizationcode()+"','"+s.getConsignmentbillmasterid()+"','"+createTime+"','"+s.getTypenum()+"','"+s.getTypename()+"','"+info+"','"+s.getSystime()+"','"+s.getCreateoperator()+"','"+s.getCreatecompanyname()+"','"+s.getDatatype()+"','"
                    +s.getOthernumber()+"','"+s.getDrivercode()+"','"+s.getDrivername()+"','"+s.getCarlicense()+"','"+s.getDeliverydate()+"','"+s.getReceiveperson()+"','"
                    +s.getDeliverycompany()+"','"+s.getArrivalqueryphone()+"','"+s.getTransfercompanysendphone()+"','"+s.getTransfercompanyreceive()+"','"+s.getLongitude()+"','"+s.getLatitude()+"')";
            sqlInsert=sqlInsert.replace("null","");
            try {
                if (s.getDatatype()!=null&&s.getDatatype()!=2){
                    jdbcDao_GoodsTracked.updateForSql(sqlInsert);
                }else{
                    log.info("跟踪类型删除:"+s.getConsignmentbillmasterid()+" "+s.getTypenum()+" "+s.getTypename());
                }
            } catch (Exception e) {
                log.info("插入货物跟踪error:",e);
                e.printStackTrace();
            }
        }
        end = System.currentTimeMillis();
        log.info("DataSource:" + dataSource + ";Databasename:" + databasename + ";货物跟踪insert：" + list.size() + ";消耗" + (end - begin) + "豪秒。");
        list=null;
        begin = System.currentTimeMillis();
        try {
            if(f6Id!=null&&f6Id.length()!=0){
                String billMasterIdS []=f6Id.split(",");
                for(int c=0;c<billMasterIdS.length;c++){
                    try{
                        String id =billMasterIdS[c];
                        if(id!=null&&id.length()!=0){
                            String f6sql =" delete from GoodsTracked_Record  where RecordID =" + id + "";
//                        log.info("delete:" + f6sql);
                            jdbcDao.updateForSql(f6sql);
                        }
                    }catch (Exception e){
                        e.printStackTrace();
                        log.error("delete1失败:" + e.getMessage());
                    }

                }

            }
//            jdbcDao.updateForSql("delete from GoodsTracked_Record where  sysTime<='" + datetime + "'");//原按时间范围删除。导致客户补跟踪数据丢失
        } catch (Exception e) {
            e.printStackTrace();
            log.error("delete失败:" + e.getMessage());
        }
        end = System.currentTimeMillis();
        log.info("DataSource:" + dataSource + ";Databasename:" + databasename + ";删除业务数据消耗" + (end - begin) + "豪秒。");
    }


    public List<GoodstrackedSetingPublic> list() {
        return goodsTrackedSetingPublicService.list();
    }

    @Override
    public void insert_car(String dataSource, String databasename, String wxpublicnumber, String appid) {
        if (wxpublicnumber == null) {
            wxpublicnumber = "";
        }
        if (appid == null) {
            appid = "";
        }

        String datetime = DateUtil.Now();

        int numTmp = 0;
        String sqlArray0 = "";
        int i = 1;

        List<GoodsTrack> listByDelete = new ArrayList<GoodsTrack>();
        Jrpt jrpt;
        String upload;


        Long begin;
        String insertSql;
        String seleclSql;
        Long end;

        //同步派车记录
        ConsignmentBillMaster consignmentBillMaster = new ConsignmentBillMaster();
        List<ConsignmentBillMaster> listByConsignmentBillMasterDelete = new ArrayList<ConsignmentBillMaster>();

        int zs=0;
        try{
            String countSql= " select count(*) count " +
                    "  from TransportBillMaster_Temp t WITH(NOLOCK) " +
                    "  left join Sys_Company c on t.OrganizationCode=c.OrganizationCode AND t.sendCompany=c.CompanyName "+
                    "  left join Sys_Company d on t.OrganizationCode=d.OrganizationCode AND t.ReceiveCompany=d.CompanyName "+
                    "  where t.SysTime<='" + datetime + "'";
            Map<String, Object> countObj =jdbcDao.querySingleResultForSql(countSql);
            if(countObj != null && countObj.get("count") != null){
                zs= Integer.valueOf(countObj.get("count").toString());
            }else if(countObj != null && countObj.get("COUNT") != null){
                zs= Integer.valueOf(countObj.get("COUNT").toString());
            }
        }catch (Exception e){

        }


        int max=10000;
        if(1==2){
            int num = zs / max;
            num = zs % max != 0 ? num + 1 : num;
            for (int j = 0; j < num; j++) {
                begin = System.currentTimeMillis();
                seleclSql = " select top "+(j*max)+" TransportBillMasterId, ISNULL( d.CompanyName, t.sendCompany) ReceiveCompany , t.*,z.FyCloudCode tenant,d.FyCloudCode endCompanyCode,z.FyCloudPassword tenantPass " +
                        "  from TransportBillMaster_Temp t WITH(NOLOCK) " +
                        "  left join Sys_Company c on t.OrganizationCode=c.OrganizationCode AND t.sendCompany=c.CompanyName "+
                        "  left join Sys_Company d on t.OrganizationCode=d.OrganizationCode AND t.ReceiveCompany=d.CompanyName "+
                        "    left join Sys_Company z on t.OrganizationCode=z.OrganizationCode and z.CompanyType='总公司'"+
                        "  where t.SysTime<='" + datetime + "'";
                // log.info(seleclSql);
                List<TransportbillmasterPublic> listByConsignmentBillMaster = jdbcDao.queryListForSql(seleclSql, TransportbillmasterPublic.class);
                end = System.currentTimeMillis();
                log.info("DataSource:" + dataSource + ";Databasename:" + databasename + ";派车单数据：" + listByConsignmentBillMaster.size() + ";消耗" + (end - begin) + "豪秒。");
                numTmp = 0;
                sqlArray0 = "";
                i = 1;
                List<TransportbillmasterPublic> deleteList=new ArrayList<TransportbillmasterPublic>();
                List<TransportbillmasterPublic> updateList=new ArrayList<TransportbillmasterPublic>();
                begin = System.currentTimeMillis();
                for (TransportbillmasterPublic s : listByConsignmentBillMaster) {
                    try {
                        try {
                            s = (TransportbillmasterPublic)killNull(s);


                            if (s.getDatatype()==0){
                                jdbcDao_GoodsTracked.insert(s);
                            }else if(s.getDatatype()==2){
                                deleteList.add(s);
                                jdbcDao_GoodsTracked.insert(s);
                            }else if(s.getDatatype()==1){
                                updateList.add(s);
                                jdbcDao_GoodsTracked.insert(s);
                            }
                        } catch (Exception e) {
                            log.info("jdbcDao_GoodsTracked", e);
                            e.printStackTrace();
                        }

                    } catch (Exception e) {
                        log.info("jdbcDao_GoodsTracked.insert", e);
                        e.printStackTrace();
                    }
                }
                end = System.currentTimeMillis();
                try {
                    //不应该注释
                    jdbcDao.updateForSql("delete from TransportBillMaster_Temp where " +
                            " where TransportBillMasterId in(select top "+(j*max)+" TransportBillMasterId from  TransportBillMaster_Temp sysTime<='" + datetime + "')");
                } catch (Exception e) {
                    e.printStackTrace();
                }
                log.info("DataSource:" + dataSource + ";Databasename:" + databasename + ";保存paich数据消耗" + (end - begin) + "豪秒。");
            }
        }else{
            String ids="";
            begin = System.currentTimeMillis();
            seleclSql = " select c.FyCloudCode startCompanyCode,ISNULL( d.CompanyName, t.sendCompany) ReceiveCompany , t.*,z.FyCloudCode tenant,d.FyCloudCode endCompanyCode,z.FyCloudPassword tenantPass " +
                    "  from TransportBillMaster_Temp t WITH(NOLOCK) " +
                    "  left join Sys_Company c on t.OrganizationCode=c.OrganizationCode AND t.sendCompany=c.CompanyName "+
                    "  left join Sys_Company d on t.OrganizationCode=d.OrganizationCode AND t.ReceiveCompany=d.CompanyName "+
                    "    left join Sys_Company z on t.OrganizationCode=z.OrganizationCode and z.CompanyType='总公司'"+
                    "  where t.SysTime<='" + datetime + "'";
            // log.info(seleclSql);
            List<TransportbillmasterPublic> listByConsignmentBillMaster = jdbcDao.queryListForSql(seleclSql, TransportbillmasterPublic.class);
            end = System.currentTimeMillis();
            log.info("DataSource:" + dataSource + ";Databasename:" + databasename + ";派车单数据：" + listByConsignmentBillMaster.size() + ";消耗" + (end - begin) + "豪秒。");
            numTmp = 0;
            sqlArray0 = "";
            i = 1;
//            List<TransportbillmasterPublic> deleteList=new ArrayList<TransportbillmasterPublic>();
//            List<TransportbillmasterPublic> updateList=new ArrayList<TransportbillmasterPublic>();
            begin = System.currentTimeMillis();
            for (TransportbillmasterPublic s : listByConsignmentBillMaster) {
                try {
                    ids+=s.getTransportbillmasterid()+",";
                    String mxSelectSql=" select t.* from TransportBillDetails_Temp t  WITH(NOLOCK) where t.TransportBillMasterId='"+s.getTransportbillmasterid()+"'";
                    String mxDelSql=" delete from TransportBillDetails_Public  where TransportBillMasterId='"+s.getTransportbillmasterid()+"'";
                    List<TransportbillDetailsPublic> listMx = jdbcDao.queryListForSql(mxSelectSql, TransportbillDetailsPublic.class);
                    try{
                        if (listMx!=null&&listMx.size()>0){
                            //先删除原有明细记录
                            jdbcDao_GoodsTracked.updateForSql(mxDelSql);
                            for(int c= 0 ; c<listMx.size();c++){
                                TransportbillDetailsPublic mx = (TransportbillDetailsPublic)listMx.get(c);
                                String insertMx=" insert into TransportBillDetails_Public (organizationcode,transportbillmasterid,transportbilldetailsid,consignmentbillmasterid,consignmentbillnumber,consignor,consignormobiletelephone,consignmentbilldate,consignoraddress,consignee,consigneemobiletelephone,consigneeaddress,totalnumberofpackages,totalweight,totalvolume,totaltransportcost,collectiongoodsvalue,datatype,systime) " +
                                        "values ('"+mx.getOrganizationcode()+"','"+mx.getTransportbillmasterid()+"','"+mx.getTransportbilldetailsid()+"','"+mx.getConsignmentbillmasterid()+"','"+mx.getConsignmentbillnumber()+"','"+mx.getConsignor()+"','"+mx.getConsignormobiletelephone()+"','"+mx.getConsignmentbilldate()+"','"+mx.getConsignoraddress()+"','"+mx.getConsignee()+"','"+mx.getConsigneemobiletelephone()+"','"+mx.getConsigneeaddress()+"','"+mx.getTotalnumberofpackages()+"','"+mx.getTotalweight()+"','"+mx.getTotalvolume()+"','"+mx.getTotaltransportcost()+"','"+mx.getCollectiongoodsvalue()+"','"+mx.getDatatype()+"','"+mx.getSystime()+"')";
                                //插入新明细记录
                                jdbcDao_GoodsTracked.updateForSql(insertMx);
                            }
                        }
                        listMx=null;
                    }catch (Exception e){
                        log.info("派车明细插入异常", e);
                        listMx=null;
                    }
                    try {
                        try{
                            s = (TransportbillmasterPublic)killNull(s);
                        }catch (Exception e){

                        }
                        String transportstartdate="";
                        if(s.getTransportstartdate()!=null){
                            transportstartdate=s.getTransportstartdate()+"";
                        }
                        String Confirmdate="";
                        if (s.getConfirmdate()!=null){
                            Confirmdate=s.getConfirmdate()+"";
                        }
                        String Arrivedate="";
                        if (s.getArrivedate()!=null){
                            Arrivedate=s.getArrivedate()+"";
                        }
                        String getReceivedate="";
                        if (s.getReceivedate()!=null){
                            getReceivedate=s.getReceivedate()+"";
                        }

                        String getYbackupdatea="";
                        if (s.getYbackupdatea()!=null){
                            getYbackupdatea=s.getYbackupdatea()+"";
                        }

                        String getYbackupdateb="";
                        if (s.getYbackupdateb()!=null){
                            getYbackupdateb=s.getYbackupdateb()+"";
                        }
                        String getYbackupdatec="";
                        if (s.getYbackupdatec()!=null){
                            getYbackupdatec=s.getYbackupdatec()+"";
                        }

                        String getYbackupdated="";
                        if (s.getYbackupdated()!=null){
                            getYbackupdated=s.getYbackupdated()+"";
                        }
                        String transportbeginlongitude="0";
                        if (s.getTransportbeginlongitude()!=null){
                            transportbeginlongitude=s.getTransportbeginlongitude()+"";
                        }
                        String transportbeginlatitude="0";
                        if (s.getTransportbeginlatitude()!=null){
                            transportbeginlatitude=s.getTransportbeginlatitude()+"";
                        }
                        String transportendlongitude="0";
                        if (s.getTransportbeginlongitude()!=null){
                            transportendlongitude=s.getTransportendlongitude()+"";
                        }
                        String transportendlatitude="0";
                        if (s.getTransportbeginlongitude()!=null){
                            transportendlatitude=s.getTransportendlatitude()+"";
                        }

                        String sql="insert into TransportBillMaster_public (organizationcode,transportbillmasterid,transportbillnumber,transportbilltype,transportstatus,transportmode,transportstartdate,predictarrivedate,confirmoperator,confirmdate,arrivedate,receiveoperator,receivedate,transportbeginplace,sendcompany,receivecompany,transportendplace,carnumber,trailernumber,drivername,copilotname,drivertelephone,copilottelephone,overseepersonnel,checkpersonnel,transportbillremark,contractnumber,totalfare,alreadyfare,arrivefare,returnfare,unloadcost,manualcost,managegoodscost,transfercost,drivercollectioncost,driveradvancecost,runlicenseno,carframenumber,driverlicensenumber,carmodelnumber,enginenumber,carrier,ybackupstringa,ybackupstringb,ybackupstringc,ybackupstringd,ybackupstringe,ybackupstringf,ybackupstringg,ybackupstringh,ybackupmoneya,ybackupmoneyb,ybackupmoneyc,ybackupmoneyd,ybackupmoneye,ybackupmoneyf,ybackupmoneyg,ybackupmoneyh,ybackupdatea,ybackupdateb,ybackupdatec,ybackupdated,dailyaccountlist,datatype,systime,transportbeginlongitude,transportbeginlatitude,transportendlongitude,transportendlatitude,consignmentbillcount,totalnumberofpackages,totalweight,totalvolume,totaltransportcost,collectiongoodsvalue,tenant,tenantpass,endcompanycode,trackingno) " +
                                " values ('"+s.getOrganizationcode()+"','"+s.getTransportbillmasterid()+"','"+s.getTransportbillnumber()+"','"+s.getTransportbilltype()+"','"+s.getTransportstatus()+"','"+s.getTransportmode()+"','"
                                +transportstartdate+"','"+s.getPredictarrivedate()+"','"+s.getConfirmoperator()+"','"
                                +Confirmdate+"','"
                                +Arrivedate+"','" +s.getReceiveoperator()+"','"
                                +getReceivedate+"','"+s.getTransportbeginplace()+"','"+s.getSendcompany()+"','"+s.getReceivecompany()+"','"+s.getTransportendplace()+"','"+s.getCarnumber()+"','"+s.getTrailernumber()+"','"+s.getDrivername()+"','"+s.getCopilotname()+"','"+s.getDrivertelephone()+"','"+s.getCopilottelephone()+"','"+s.getOverseepersonnel()+"','"+s.getCheckpersonnel()+"','"+s.getTransportbillremark()+"','"+s.getContractnumber()+"','"+s.getTotalfare()+"','"+s.getAlreadyfare()+"','"+s.getArrivefare()+"','"+s.getReturnfare()+"','"+s.getUnloadcost()+"','"+s.getManualcost()+"','"+s.getManagegoodscost()+"','"+s.getTransfercost()+"','"+s.getDrivercollectioncost()+"','"+s.getDriveradvancecost()+"','"+s.getRunlicenseno()+"','"+s.getCarframenumber()+"','"+s.getDriverlicensenumber()+"','"+s.getCarmodelnumber()+"','"+s.getEnginenumber()+"','"+s.getCarrier()+"','"+s.getYbackupstringa()+"','"+s.getYbackupstringb()+"','"+s.getYbackupstringc()+"','"+s.getYbackupstringd()+"','"+s.getYbackupstringe()+"','"+s.getYbackupstringf()+"','"+s.getYbackupstringg()+"','"+s.getYbackupstringh()+"','"+s.getYbackupmoneya()+"','"+s.getYbackupmoneyb()+"','"+s.getYbackupmoneyc()+"','"+s.getYbackupmoneyd()+"','"+s.getYbackupmoneye()+"','"+s.getYbackupmoneyf()+"','"+s.getYbackupmoneyg()+"','"+s.getYbackupmoneyh()+"','"
                                +getYbackupdatea+"','"
                                +getYbackupdateb+"','"
                                +getYbackupdatec+"','"
                                +getYbackupdated+"','"+s.getDailyaccountlist()+"','"
                                +s.getDatatype()+"','"
                                +transportstartdate+"'" +
                                ",'"+transportbeginlongitude+"','"+transportbeginlatitude+"','"+transportendlongitude+"','"+transportendlatitude+"','"
                                +s.getConsignmentbillcount()+"','"+s.getTotalnumberofpackages()+"','"+s.getTotalweight()+"','"+s.getTotalvolume()+"','"+s.getTotaltransportcost()+"','"+s.getCollectiongoodsvalue()+"','"+s.getTenant()+"','"+s.getTenantpass()+"','"+s.getEndcompanycode()+"','"+s.getTrackingno()+"')";


                        sql=sql.replace("null","");
                        if (s.getDatatype()==0){
                            jdbcDao_GoodsTracked.updateForSql(sql);
//                            jdbcDao_GoodsTracked.insert(s);
                        }else if(s.getDatatype()==2){
//                            deleteList.add(s);
//                            jdbcDao_GoodsTracked.insert(s);
                            jdbcDao_GoodsTracked.updateForSql(sql);
                        }else if(s.getDatatype()==1){
//                            updateList.add(s);
//                            jdbcDao_GoodsTracked.insert(s);
                            jdbcDao_GoodsTracked.updateForSql(sql);
                        }
                    } catch (Exception e) {
                        log.info("jdbcDao_GoodsTracked", e);
                        e.printStackTrace();
                    }


                } catch (Exception e) {
                    log.info("jdbcDao_GoodsTracked.insert", e);
                    e.printStackTrace();
                }
            }
            listByConsignmentBillMaster=null;
            end = System.currentTimeMillis();
            try {
                //不应该注释
                jdbcDao.updateForSql("delete from TransportBillMaster_Temp where  sysTime<='" + datetime + "'");
                if (ids!=null&&ids.length()!=0){
                    String idlist [] = ids.split(",");
                    if (idlist!=null&&idlist.length>0){
                        for(int d=0;d<idlist.length;d++){
                            if (idlist[d]!=null&&idlist[d].length()>0){
                                jdbcDao.updateForSql("delete from TransportBillDetails_Temp where  TransportBillMasterId ='" + idlist[d] + "'");
                            }
                        }
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
            log.info("DataSource:" + dataSource + ";Databasename:" + databasename + ";保存paich数据消耗" + (end - begin) + "豪秒。");
        }
    }
    @Override
    public void insert_CollectingMoney(String dataSource, String databasename, String wxpublicnumber, String appid) {
        if (wxpublicnumber == null) {
            wxpublicnumber = "";
        }
        if (appid == null) {
            appid = "";
        }
        String datetime = DateUtil.Now();
        int numTmp = 0;
        String sqlArray0 = "";
        int i = 1;
        List<GoodsTrack> listByDelete = new ArrayList<GoodsTrack>();
        Jrpt jrpt;
        String upload;
        Long begin;
        String insertSql;
        String seleclSql;
        Long end;
        //同步代收记录
        ConsignmentBillMaster consignmentBillMaster = new ConsignmentBillMaster();

        String ConsignmentBillMasterIdStr = "";


        if(1==2){

        }else{
            begin = System.currentTimeMillis();
            seleclSql = " select " +
                    "  CASE WHEN isnull(bf.GTConsignmentBillMasterId,'')<>'' then bf.GTConsignmentBillMasterId ELSE t.ConsignmentBillMasterId END  AS  ConsignmentBillMasterIdNew,t.*" +
                    ",case when isnull(bf.FyCloudCode,'')='' then z.FyCloudCode else bf.FyCloudCode end as tenant," +
                    "case when isnull(bf.FyCloudPassword,'')='' then z.FyCloudPassword else bf.FyCloudPassword end tenantPass," +
                    "(CASE WHEN GiveDate IS NULL THEN '未发放' WHEN GiveType='现金' THEN '已发放'  WHEN FileExportDate IS NULL THEN '已发放' WHEN TransferAccountResult='成功' THEN '转账成功' WHEN TransferAccountResult='失败' THEN '转账失败' ELSE '已导出' END) AS DataStatus ," +
                    "(case when (IsNull(CollectionGoodsValue,0)-IsNull(CollectionGoodsValueDec,0) - IsNull(DeductionTransportCost,0)- IsNull(CollectionGoodsValueInc,0))<0 then 0 else (IsNull(CollectionGoodsValue,0)-IsNull(CollectionGoodsValueDec,0) - IsNull(DeductionTransportCost,0)- IsNull(CollectionGoodsValueInc,0)) End -IsNull(SettlementInsuranceCost,0)-IsNull(ExtraCost,0)-IsNull(ExceedExtraCost,0)-IsNull(LoseExtraCost,0)-IsNull(ShortMessageCharge,0)-IsNull(ExtraCostOverCharge,0)+IsNull(ExtraCostDecreaseCharge,0)-IsNull(SettlementFuelCost,0) ) paymentmoney ,IsNull(SettlementFuelCost,0) as SettlementFuelCost"+
                    "  from CollectionGoodsValueAccount_Temp t WITH(NOLOCK)  " +
                    "  left join Sys_Company c on t.OrganizationCode=c.OrganizationCode AND t.sendCompany=c.CompanyName "+
                    "    left join Sys_Company z on t.OrganizationCode=z.OrganizationCode and z.CompanyType='总公司'"+
                    "    LEFT JOIN CooCompanyRelationInfo bf WITH(NOLOCK) ON t.OrganizationCode=bf.OrganizationCode AND t.ConsignmentBillNumber=bf.ConsignmentBillNumber " +
                    " " +
                    " where t.SysTime<='" + datetime + "' order by t.SysTime " +
                    "";
            List<CollectiongoodsvalueaccountPublic> listByConsignmentBillMaster = jdbcDao.queryListForSql(seleclSql, CollectiongoodsvalueaccountPublic.class);
            end = System.currentTimeMillis();
            log.info("DataSource:" + dataSource + ";Databasename:" + databasename + ";代收数据：" + listByConsignmentBillMaster.size() + ";消耗" + (end - begin) + "豪秒。");
            numTmp = 0;
            sqlArray0 = "";
            i = 1;
            begin = System.currentTimeMillis();
            boolean test=false;
            for (CollectiongoodsvalueaccountPublic s : listByConsignmentBillMaster) {
                if (ConsignmentBillMasterIdStr==null||ConsignmentBillMasterIdStr.length()==0){
                    ConsignmentBillMasterIdStr="'"+s.getCollectiongoodsvalueaccountid()+"'";
                } else {
                    ConsignmentBillMasterIdStr=ConsignmentBillMasterIdStr+","+"'"+s.getCollectiongoodsvalueaccountid()+"'";
                }
                String  obtainsystime="";
                if (s.getObtainsystime()!=null){
                    obtainsystime=s.getObtainsystime()+"";
                    if(obtainsystime.length()>19){
                        obtainsystime=obtainsystime.substring(0,19);
                    }
                }
                String  returnmoneydate="";//回款日期
                if (s.getReturnmoneydate()!=null){
                    returnmoneydate=s.getReturnmoneydate()+"";
                    if(returnmoneydate.length()>19){
                        returnmoneydate=returnmoneydate.substring(0,19);
                    }
                }
                String  givedate="";//支付日期  F6转账日期
                if (s.getGivedate()!=null&&!"NULL".equals(s.getGivedate())){
                    givedate=s.getGivedate()+"";
                    if(givedate.length()>19){
                        givedate=givedate.substring(0,19);
                    }
                    givedate="'"+givedate+"'";
                }else{
                    givedate="NULL";
                }
                String  consignmentbilldate="";
                if (s.getConsignmentbilldate()!=null){
                    consignmentbilldate=s.getConsignmentbilldate()+"";
                    if(consignmentbilldate.length()>19){
                        consignmentbilldate=consignmentbilldate.substring(0,19);
                    }
                }
                String systime="";
                if (s.getSystime()!=null){
                    systime=s.getSystime()+"";
                    if(systime.length()>19){
                        systime=systime.substring(0,19);
                    }
                }
                String consignor=s.getConsignor();
                if (consignor!=null&&consignor.length()!=0){
                    consignor=consignor.replace("'","");
                }
                String consignee=s.getConsignee();
                if (consignee!=null&&consignee.length()!=0){
                    consignee=consignee.replace("'","");
                }


                String isnerSql="insert into CollectionGoodsValueAccount_Public (TransferAccountResult,ExtraCost,organizationcode,collectiongoodsvalueaccountid,consignmentbillmasterid,obtainsystime,consignmentbillnumber,manualnumber,goodsnumber,returnmoneydate,givedate,consignmentbilldate,onecardcode,account,consignee,consigneemobiletelephone,consigneetelephone,consignor,consignormobiletelephone,consignortelephone,accountholder,shortmessagemobiletelephone,givetype,thirdpartycompany,exceedextracost,loseextracost,extracostovercharge,extracostdecreasecharge,collectiongoodsvalue,deductiontransportcost,collectiongoodsvaluedec,settlementinsurancecost,paymentmoney,shortmessagecharge,bankname,traceplatformid,datatype,tenant,tenantpass" +
                        ",systime,flag,trackingno,datastatus,collectiongoodsvaluetype,settlementfuelcost) " +
                        " values ('"+s.getTransferaccountresult()+"','"+s.getExtracost()+"','"+s.getOrganizationcode()+"','"+s.getCollectiongoodsvalueaccountid()+"','"+s.getConsignmentbillmasteridnew()+"','"+
                        obtainsystime+"','"+s.getConsignmentbillnumber()+"','"+s.getManualnumber()+"','"+s.getGoodsnumber()+"','"+
                        returnmoneydate+"',"+givedate+",'"+consignmentbilldate+"','"+s.getOnecardcode()+"','"+s.getAccount()+"','"
                        +consignee+"','"+s.getConsigneemobiletelephone()+"','"+s.getConsigneetelephone()+"','"
                        +consignor+"','"+s.getConsignormobiletelephone()+"','"+s.getConsignortelephone()+"','"+s.getAccountholder()+"','"+s.getShortmessagemobiletelephone()+"','"+s.getGivetype()+"','"+s.getThirdpartycompany()+"','"+s.getExceedextracost()+"','"+s.getLoseextracost()+"','"+s.getExtracostovercharge()+"','"+s.getExtracostdecreasecharge()+"','"+s.getCollectiongoodsvalue()+"','"+s.getDeductiontransportcost()+"','"+s.getCollectiongoodsvaluedec()+"','"+s.getSettlementinsurancecost()+"','"+s.getPaymentmoney()+"','"+s.getShortmessagecharge()+"','"+s.getBankname()+"','"+s.getTraceplatformid()+"',"+s.getDatatype()+",'"+s.getTenant()+"','"+s.getTenantpass()+"','"+
                        systime+"','"+s.getFlag()+"','"+s.getTrackingno()+"','"+s.getDatastatus()+"','"+s.getCollectiongoodsvaluetype()+"','"+s.getSettlementfuelcost()+"')";
                isnerSql=isnerSql.replace("null","");
                if("F6TEST".equals(databasename)||"f6test".equals(databasename)){
                    test=true;
                    log.info("CollectiongoodsvalueaccountPublic:"+JSONObject.toJSONString(databasename));
                    log.info("代收 isnerSql:"+isnerSql);
                    log.info("发放日期："+s.getGivedate());
                }
                try {
                    try {
//                        s = (CollectiongoodsvalueaccountPublic)killNull(s);
                        if (s.getDatatype()==0){
//                           Long a= jdbcDao_GoodsTracked.insert(s);
                           int a= jdbcDao_GoodsTracked.updateForSql(isnerSql);
                           if (test){
                               log.info("save:"+s.getConsignmentbillnumber()+a);
                           }
                        }else if(s.getDatatype()==1){
                            String sql ="update CollectionGoodsValueAccount_Public " +
                                    " set flag='',flagnew='',dataType='1',dataStatus='"+ s.getDatastatus() +"'  where CollectionGoodsValueAccountId='"+s.getCollectiongoodsvalueaccountid()+"'";
                            jdbcDao_GoodsTracked.updateForSql(sql);
                        }else if(s.getDatatype()==2){
                            String sql ="update CollectionGoodsValueAccount_Public " +
                                    " set flagnew='',flag='',dataType='2' where CollectionGoodsValueAccountId='"+s.getCollectiongoodsvalueaccountid()+"'";
                            jdbcDao_GoodsTracked.updateForSql(sql);
                            log.error("dshk sql:"+sql);
                        }
                    } catch (Exception e) {
                        log.info("insert_CollectingMoney", e);
                        e.printStackTrace();
                    }

                } catch (Exception e) {
                    log.info("insert_CollectingMoney.insert", e);
                    e.printStackTrace();
                }
            }
            end = System.currentTimeMillis();
            log.info("DataSource:" + dataSource + ";Databasename:" + databasename + ";保存代收数据消耗" + (end - begin) + "豪秒。");
            try {
                //不应该注释
                if(ConsignmentBillMasterIdStr!=null&&ConsignmentBillMasterIdStr.length()!=0){
                    String billMasterIdS []=ConsignmentBillMasterIdStr.split(",");
                    for(int c=0;c<billMasterIdS.length;c++){
                        String id =billMasterIdS[c];
                        if(id!=null&&id.length()!=0){
                            String f6sql =" delete from CollectionGoodsValueAccount_Temp  where collectiongoodsvalueaccountid =" + id + "";
                            log.info("deleteF6:" + f6sql);
                            jdbcDao.updateForSql(f6sql);
                        }
                    }

                }
//                jdbcDao.updateForSql("delete from CollectionGoodsValueAccount_Temp where  sysTime<='" + datetime + "'");
            } catch (Exception e) {
                e.printStackTrace();
            }
        }



    }
    public static Object killNull(Object object) throws Exception {
        //遍历object类 成员为String类型 属性为空的全部替换为""
        Field[] fields = object.getClass().getDeclaredFields();
        try{
            String inserSql=" insert into CollectionGoodsValueAccount_Public ";
            String str="";
            String strVal="";
            for (int i = 0; i < fields.length; i++) {
                // 获取属性的名字
                String name = fields[i].getName();
                str=str+","+name;
                strVal=strVal+",get"+name.substring(0,1).toUpperCase()+name.substring(1,name.length())+"()";
                // 将属性的首字符大写，方便构造get，set方法
                name = name.substring(0, 1).toUpperCase() + name.substring(1);
                // 获取属性的类型
                String type = fields[i].getGenericType().toString();
//            System.out.println(name+" "+type);
                // 如果type是类类型，则前面包含"class "，后面跟类名
                if (type.equals("class java.lang.String")) {
                    Method m = object.getClass().getMethod("get" + name);
                    // 调用getter方法获取属性值
                    String value = (String) m.invoke(object);
                    if (value == null) {
                        Class[] parameterTypes = new Class[1];
                        parameterTypes[0] = fields[i].getType();
                        m = object.getClass().getMethod("set" + name, parameterTypes);
                        String string = new String("");
                        Object[] objects = new Object[1];
                        objects[0] = string;
                        m.invoke(object, objects);
                    }
                }else if(type.equals("class java.math.BigDecimal")){
                    Method m = object.getClass().getMethod("get" + name);
                    // 调用getter方法获取属性值
                    BigDecimal value = (BigDecimal) m.invoke(object);
                    if (value == null) {
                        Class[] parameterTypes = new Class[1];
                        parameterTypes[0] = fields[i].getType();
                        m = object.getClass().getMethod("set" + name, parameterTypes);
                        BigDecimal bigDecimal = new BigDecimal(0);
                        Object[] objects = new Object[1];
                        objects[0] = bigDecimal;
                        m.invoke(object, objects);
                    }
                }else if(type.equals(" class java.lang.Integer")){
                    Method m = object.getClass().getMethod("get" + name);
                    // 调用getter方法获取属性值
                    Integer value = (Integer) m.invoke(object);
                    if (value == null) {
                        Class[] parameterTypes = new Class[1];
                        parameterTypes[0] = fields[i].getType();
                        m = object.getClass().getMethod("set" + name, parameterTypes);
                        Integer integer = new Integer(0);
                        Object[] objects = new Object[1];
                        objects[0] = integer;
                        m.invoke(object, objects);
                    }
                }
                //将形参object类中在com.yu.killnull包下的引用一块遍历修改
                if (type.contains("class com.yu.killnull")) {
                    Method m = object.getClass().getMethod("get" + name);
                    // 调用getter方法获取属性值
                    Object value = m.invoke(object);
                    killNull(value);
                }
            }
        }catch (Exception e){
            log.error("kill null:"+e);

        }


        return object;

    }
    @Override
    public void insert_car_buchuan(String dataSource, String databasename, String wxpublicnumber, String appid
            ,String CreateTimeBegin,String CreateTimeEnd,String OrganizationCode) {
        if (wxpublicnumber == null) {
            wxpublicnumber = "";
        }
        if (appid == null) {
            appid = "";
        }
        String sqlArray0 = "";
        List<GoodsTrack> listByDelete = new ArrayList<GoodsTrack>();
        Long begin;
        String seleclSql;
        Long end;
        begin = System.currentTimeMillis();

        try{
            List<Jrpt> jrpts = jrptService.select();
            for (Jrpt jrpt : jrpts) {
                if(jrpt!=null&&jrpt.getOrganizationcode()!=null&&jrpt.getOrganizationcode().length()!=0){
                    int listNum=0;
                    OrganizationCode=jrpt.getOrganizationcode();
                    seleclSql=" select c.FyCloudCode startCompanyCode,ISNULL( c.CompanyName, b.CompanyName) ReceiveCompany,z.FyCloudCode tenant, ISNULL(c.FyCloudCode, b.FyCloudCode) endCompanyCode,z.FyCloudPassword tenantPass ,a.OrganizationCode,a.TransportBillMasterId,TransportBillNumber,TransportBillType,TransportStatus    " +
                            "      ,TransportMode,TransportStartDate,PredictArriveDate,ConfirmOperator,ConfirmDate,ArriveDate   " +
                            "      ,ReceiveOperator,ReceiveDate,TransportBeginPlace,SendCompany,TransportEndPlace  " +
                            "      ,CarNumber,TrailerNumber,DriverName,CopilotName,DriverTelephone,CopilotTelephone,OverseePersonnel   " +
                            "      ,CheckPersonnel,TransportBillRemark,ContractNumber,TotalFare,AlreadyFare,ArriveFare,ReturnFare   " +
                            "      ,UnloadCost,ManualCost,ManageGoodsCost,TransferCost,DriverCollectionCost,DriverAdvanceCost,RunLicenseNo,CarFrameNumber  " +
                            "      ,DriverLicenseNumber,CarModelNumber,EngineNumber,Carrier,YBackupStringA,YBackupStringB,YBackupStringC,YBackupStringD,YBackupStringE,YBackupStringF " +
                            "      ,YBackupStringG,YBackupStringH,YBackupMoneyA,YBackupMoneyB,YBackupMoneyC,YBackupMoneyD,YBackupMoneyE,YBackupMoneyF " +
                            "      ,YBackupMoneyG,YBackupMoneyH,YBackupDateA,YBackupDateB,YBackupDateC,YBackupDateD,DailyAccountList, " +
                            "      0 AS DataType,GETDATE() SysTime," +
                            " convert(decimal(18,0),ISNULL(b.Longitude,'0')) TransportBeginLongitude," +
                            " convert(decimal(18,0),ISNULL(b.Latitude,'0')) TransportBeginLatitude," +
                            "  convert(decimal(18,0),ISNULL(c.Longitude,'0')) TransportEndLongitude, " +
                            "    convert(decimal(18,0),ISNULL(c.Latitude,'0'))   TransportEndLatitude,ConsignmentBillCount,TotalNumberOfPackages,TotalWeight,TotalVolume,TotalTransportCost,CollectionGoodsValue  " +
                            "      from TransportBillMaster as a WITH(NOLOCK) left join (select TransportBillMasterId,count(TransportBillMasterId) as ConsignmentBillCount " +
                            "     ,sum(TotalNumberOfPackages) as TotalNumberOfPackages,sum(TotalWeight) as TotalWeight,sum(TotalVolume) as TotalVolume,sum(TotalTransportCost) as TotalTransportCost " +
                            "     ,sum(CollectionGoodsValue) as CollectionGoodsValue from TransportBillDetails aa WITH(NOLOCK) inner join ConsignmentBillMaster bb WITH(NOLOCK) on aa.ConsignmentBillMasterId=bb.ConsignmentBillMasterId " +
                            "      group by TransportBillMasterId) trans on a.TransportBillMasterId=trans.TransportBillMasterId  " +
                            "      left join(select * from Sys_Company as b WITH(NOLOCK) where OrganizationCode='"+OrganizationCode+"' ) b on a.TransportBeginPlace=b.CompanyName " +
                            "      left join (select * from Sys_Company as c WITH(NOLOCK) where OrganizationCode='"+OrganizationCode+"') c on a.TransportEndPlace=c.CompanyName " +
                            "      left join Sys_Company z WITH(NOLOCK) on a.OrganizationCode=z.OrganizationCode and z.OrganizationCode='"+OrganizationCode+"' and z.CompanyType='总公司'"+
                            "      where  a.TransportStartDate>='"+CreateTimeBegin+"'" +
                            "  AND a.TransportStartDate<='"+CreateTimeEnd+"' AND a.OrganizationCode='"+OrganizationCode+"'"+
                            "      UNION  " +
                            "       select c.FyCloudCode startCompanyCode,ISNULL( c.CompanyName, b.CompanyName) ReceiveCompany,z.FyCloudCode tenant, ISNULL(c.FyCloudCode, b.FyCloudCode)  endCompanyCode,z.FyCloudPassword tenantPass ,a.OrganizationCode,a.TransportBillMasterId,TransportBillNumber,TransportBillType,TransportStatus    " +
                            "      ,TransportMode,TransportStartDate,PredictArriveDate,ConfirmOperator,ConfirmDate,ArriveDate   " +
                            "      ,ReceiveOperator,ReceiveDate,TransportBeginPlace,SendCompany,TransportEndPlace  " +
                            "      ,CarNumber,TrailerNumber,DriverName,CopilotName,DriverTelephone,CopilotTelephone,OverseePersonnel   " +
                            "      ,CheckPersonnel,TransportBillRemark,ContractNumber,TotalFare,AlreadyFare,ArriveFare,ReturnFare  \n" +
                            "      ,UnloadCost,ManualCost,ManageGoodsCost,TransferCost,DriverCollectionCost,DriverAdvanceCost,RunLicenseNo,CarFrameNumber \n" +
                            "      ,DriverLicenseNumber,CarModelNumber,EngineNumber,Carrier,YBackupStringA,YBackupStringB,YBackupStringC,YBackupStringD,YBackupStringE,YBackupStringF \n" +
                            "      ,YBackupStringG,YBackupStringH,YBackupMoneyA,YBackupMoneyB,YBackupMoneyC,YBackupMoneyD,YBackupMoneyE,YBackupMoneyF \n" +
                            "      ,YBackupMoneyG,YBackupMoneyH,YBackupDateA,YBackupDateB,YBackupDateC,YBackupDateD,DailyAccountList,\n" +
                            "      0,GETDATE()," +
                            "  convert(decimal(18,0),ISNULL(b.Longitude,'0')) ," +
                            " convert(decimal(18,0),ISNULL(b.Latitude,'0'))," +
                            " convert(decimal(18,0),ISNULL(c.Longitude,'0'))," +
                            "  convert(decimal(18,0),ISNULL(c.Latitude,'0'))," +
                            "ConsignmentBillCount,TotalNumberOfPackages,TotalWeight,TotalVolume,TotalTransportCost,CollectionGoodsValue \n" +
                            "      from OrderTransportMaster as a WITH(NOLOCK) left join (select TransportBillMasterId,count(TransportBillMasterId) as ConsignmentBillCount\n" +
                            "     ,sum(TotalNumberOfPackages) as TotalNumberOfPackages,sum(TotalWeight) as TotalWeight,sum(TotalVolume) as TotalVolume,sum(TotalTransportCost) as TotalTransportCost\n" +
                            "     ,sum(CollectionGoodsValue) as CollectionGoodsValue from OrderTransportDetails aa WITH(NOLOCK) inner join OrderBillMaster bb WITH(NOLOCK) on aa.OrderBillMasterId=bb.OrderBillMasterId\n" +
                            "      group by TransportBillMasterId) trans on a.TransportBillMasterId=trans.TransportBillMasterId \n" +
                            "      left join(select * from Sys_Company as b WITH(NOLOCK) where OrganizationCode='"+OrganizationCode+"' ) b on a.TransportBeginPlace=b.CompanyName\n" +
                            "      left join (select * from Sys_Company as c WITH(NOLOCK) where OrganizationCode='"+OrganizationCode+"') c on a.TransportEndPlace=c.CompanyName\n" +
                            "      left join Sys_Company z WITH(NOLOCK) on a.OrganizationCode=z.OrganizationCode and z.OrganizationCode='"+OrganizationCode+"' and z.CompanyType='总公司'"+
                            "      where a.TransportStartDate>='"+CreateTimeBegin+"'" +
                            " AND a.TransportStartDate<='"+CreateTimeEnd+"' AND a.OrganizationCode='"+OrganizationCode+"'";
//                    log.info("pcmb sql:"+seleclSql);
                    List<TransportbillmasterPublic> listByConsignmentBillMaster = jdbcDao.queryListForSql(seleclSql, TransportbillmasterPublic.class);
                    listNum=listByConsignmentBillMaster.size();
                    String numSql="";
                    int num=0;

                    for (TransportbillmasterPublic s : listByConsignmentBillMaster) {
                        String TransportBillMasterId= s.getTransportbillmasterid();
                        try {
                            try{
                                String transportstartdate="";
                                if(s.getTransportstartdate()!=null){
                                    transportstartdate=s.getTransportstartdate()+"";
                                }
                                String Confirmdate="";
                                if (s.getConfirmdate()!=null){
                                    Confirmdate=s.getConfirmdate()+"";
                                }
                                String Arrivedate="";
                                if (s.getArrivedate()!=null){
                                    Arrivedate=s.getArrivedate()+"";
                                }
                                String getReceivedate="";
                                if (s.getReceivedate()!=null){
                                    getReceivedate=s.getReceivedate()+"";
                                }

                                String getYbackupdatea="";
                                if (s.getYbackupdatea()!=null){
                                    getYbackupdatea=s.getYbackupdatea()+"";
                                }

                                String getYbackupdateb="";
                                if (s.getYbackupdateb()!=null){
                                    getYbackupdateb=s.getYbackupdateb()+"";
                                }
                                String getYbackupdatec="";
                                if (s.getYbackupdatec()!=null){
                                    getYbackupdatec=s.getYbackupdatec()+"";
                                }

                                String getYbackupdated="";
                                if (s.getYbackupdated()!=null){
                                    getYbackupdated=s.getYbackupdated()+"";
                                }
                                String transportbeginlongitude="0";
                                if (s.getTransportbeginlongitude()!=null){
                                    transportbeginlongitude=s.getTransportbeginlongitude()+"";
                                }
                                String transportbeginlatitude="0";
                                if (s.getTransportbeginlatitude()!=null){
                                    transportbeginlatitude=s.getTransportbeginlatitude()+"";
                                }
                                String transportendlongitude="0";
                                if (s.getTransportbeginlongitude()!=null){
                                    transportendlongitude=s.getTransportendlongitude()+"";
                                }
                                String transportendlatitude="0";
                                if (s.getTransportbeginlongitude()!=null){
                                    transportendlatitude=s.getTransportendlatitude()+"";
                                }

                                String sql="insert into TransportBillMaster_public (organizationcode,transportbillmasterid,transportbillnumber,transportbilltype,transportstatus,transportmode,transportstartdate,predictarrivedate,confirmoperator,confirmdate,arrivedate,receiveoperator,receivedate,transportbeginplace,sendcompany,receivecompany,transportendplace,carnumber,trailernumber,drivername,copilotname,drivertelephone,copilottelephone,overseepersonnel,checkpersonnel,transportbillremark,contractnumber,totalfare,alreadyfare,arrivefare,returnfare,unloadcost,manualcost,managegoodscost,transfercost,drivercollectioncost,driveradvancecost,runlicenseno,carframenumber,driverlicensenumber,carmodelnumber,enginenumber,carrier,ybackupstringa,ybackupstringb,ybackupstringc,ybackupstringd,ybackupstringe,ybackupstringf,ybackupstringg,ybackupstringh,ybackupmoneya,ybackupmoneyb,ybackupmoneyc,ybackupmoneyd,ybackupmoneye,ybackupmoneyf,ybackupmoneyg,ybackupmoneyh,ybackupdatea,ybackupdateb,ybackupdatec,ybackupdated,dailyaccountlist,datatype,systime,transportbeginlongitude,transportbeginlatitude,transportendlongitude,transportendlatitude,consignmentbillcount,totalnumberofpackages,totalweight,totalvolume,totaltransportcost,collectiongoodsvalue,tenant,tenantpass,endcompanycode,trackingno) " +
                                        " values ('"+s.getOrganizationcode()+"','"+s.getTransportbillmasterid()+"','"+s.getTransportbillnumber()+"','"+s.getTransportbilltype()+"','"+s.getTransportstatus()+"','"+s.getTransportmode()+"','"
                                        +transportstartdate+"','"+s.getPredictarrivedate()+"','"+s.getConfirmoperator()+"','"
                                        +Confirmdate+"','"
                                        +Arrivedate+"','" +s.getReceiveoperator()+"','"
                                        +getReceivedate+"','"+s.getTransportbeginplace()+"','"+s.getSendcompany()+"','"+s.getReceivecompany()+"','"+s.getTransportendplace()+"','"+s.getCarnumber()+"','"+s.getTrailernumber()+"','"+s.getDrivername()+"','"+s.getCopilotname()+"','"+s.getDrivertelephone()+"','"+s.getCopilottelephone()+"','"+s.getOverseepersonnel()+"','"+s.getCheckpersonnel()+"','"+s.getTransportbillremark()+"','"+s.getContractnumber()+"','"+s.getTotalfare()+"','"+s.getAlreadyfare()+"','"+s.getArrivefare()+"','"+s.getReturnfare()+"','"+s.getUnloadcost()+"','"+s.getManualcost()+"','"+s.getManagegoodscost()+"','"+s.getTransfercost()+"','"+s.getDrivercollectioncost()+"','"+s.getDriveradvancecost()+"','"+s.getRunlicenseno()+"','"+s.getCarframenumber()+"','"+s.getDriverlicensenumber()+"','"+s.getCarmodelnumber()+"','"+s.getEnginenumber()+"','"+s.getCarrier()+"','"+s.getYbackupstringa()+"','"+s.getYbackupstringb()+"','"+s.getYbackupstringc()+"','"+s.getYbackupstringd()+"','"+s.getYbackupstringe()+"','"+s.getYbackupstringf()+"','"+s.getYbackupstringg()+"','"+s.getYbackupstringh()+"','"+s.getYbackupmoneya()+"','"+s.getYbackupmoneyb()+"','"+s.getYbackupmoneyc()+"','"+s.getYbackupmoneyd()+"','"+s.getYbackupmoneye()+"','"+s.getYbackupmoneyf()+"','"+s.getYbackupmoneyg()+"','"+s.getYbackupmoneyh()+"','"
                                        +getYbackupdatea+"','"
                                        +getYbackupdateb+"','"
                                        +getYbackupdatec+"','"
                                        +getYbackupdated+"','"+s.getDailyaccountlist()+"','"
                                        +s.getDatatype()+"','"
                                        +transportstartdate+"'" +
                                        ",'"+transportbeginlongitude+"','"+transportbeginlatitude+"','"+transportendlongitude+"','"+transportendlatitude+"','"
                                        +s.getConsignmentbillcount()+"','"+s.getTotalnumberofpackages()+"','"+s.getTotalweight()+"','"+s.getTotalvolume()+"','"+s.getTotaltransportcost()+"','"+s.getCollectiongoodsvalue()+"','"+s.getTenant()+"','"+s.getTenantpass()+"','"+s.getEndcompanycode()+"','"+s.getTrackingno()+"')";


                                sql=sql.replace("null","");
                            jdbcDao_GoodsTracked.updateForSql(sql);
//                                jdbcDao_GoodsTracked.insert(s);
                            }catch (Exception e){
                                log.error("car error:",e);
                            }
                            List<TransportbillDetailsPublic> listMx = null;
                            String mxsql="select aa.organizationcode,aa.transportbillmasterid,aa.transportbilldetailsid,bb.consignmentbillmasterid,consignmentbillnumber    \n" +
                                    "  ,consignor,consignormobiletelephone,consignmentbilldate,case when consignoraddress='' then placeofloading else consignoraddress end,consignee,consigneemobiletelephone   \n" +
                                    " ,case when consigneeaddress='' then unloadplace else consigneeaddress end,totalnumberofpackages,totalweight,totalvolume,totaltransportcost,collectiongoodsvalue,0 as datatype,getdate() as systime\n" +
                                    "  from ordertransportdetails aa with(nolock) inner join orderbillmaster bb with(nolock) on aa.orderbillmasterid=bb.orderbillmasterid\n" +
                                    "   where aa.transportbillmasterid ='"+TransportBillMasterId+"' " +
                                    " UNION  " +
                                    " select aa.organizationcode,aa.transportbillmasterid,aa.transportbilldetailsid,bb.consignmentbillmasterid,consignmentbillnumber    \n" +
                                    "  ,consignor,consignormobiletelephone,consignmentbilldate,case when consignoraddress='' then placeofloading else consignoraddress end,consignee,consigneemobiletelephone   \n" +
                                    " ,case when consigneeaddress='' then unloadplace else consigneeaddress end,totalnumberofpackages,totalweight,totalvolume,totaltransportcost,collectiongoodsvalue,0 as datatype,getdate() as systime\n" +
                                    "  from transportbilldetails aa with(nolock) inner join consignmentbillmaster bb with(nolock) on aa.consignmentbillmasterid=bb.consignmentbillmasterid\n" +
                                    "   where aa.transportbillmasterid ='"+TransportBillMasterId+"'";
                            try{
                                listMx = jdbcDao.queryListForSql(mxsql, TransportbillDetailsPublic.class);
                                if (listMx!=null&&listMx.size()>0){
                                    if (listMx!=null&&listMx.size()>0){
                                        String mxDelSql=" delete from TransportBillDetails_Public  where TransportBillMasterId='"+TransportBillMasterId+"'";
                                        for(int c= 0 ; c<listMx.size();c++){
                                            TransportbillDetailsPublic mx = (TransportbillDetailsPublic)listMx.get(c);
                                            String consignor= mx.getConsignor();
                                            if (consignor!=null&&consignor.length()!=0){
                                                consignor=consignor.replace("'","");
                                            }
                                            String consignee=mx.getConsignee();
                                            if (consignee!=null&&consignee.length()!=0){
                                                consignee = consignee.replace("'","");
                                            }
                                            String insertMx=" insert into TransportBillDetails_Public (organizationcode,transportbillmasterid,transportbilldetailsid,consignmentbillmasterid,consignmentbillnumber,consignor,consignormobiletelephone,consignmentbilldate,consignoraddress,consignee,consigneemobiletelephone,consigneeaddress,totalnumberofpackages,totalweight,totalvolume,totaltransportcost,collectiongoodsvalue,datatype,systime) " +
                                                    "values ('"+mx.getOrganizationcode()+"','"+mx.getTransportbillmasterid()+"','"+mx.getTransportbilldetailsid()+"','"+mx.getConsignmentbillmasterid()+"','"+mx.getConsignmentbillnumber()+"','"
                                                    +consignor+"','"+mx.getConsignormobiletelephone()+"','"+mx.getConsignmentbilldate()+"','"+mx.getConsignoraddress()+"','"
                                                    +consignee+"','"+mx.getConsigneemobiletelephone()+"','"+mx.getConsigneeaddress()+"','"+mx.getTotalnumberofpackages()+"','"+mx.getTotalweight()+"','"+mx.getTotalvolume()+"','"+mx.getTotaltransportcost()+"','"+mx.getCollectiongoodsvalue()+"','"+mx.getDatatype()+"','"+mx.getSystime()+"')";
                                            //插入新明细记录
                                            try{
                                                jdbcDao_GoodsTracked.updateForSql(insertMx);
                                            }catch (Exception e){
                                                log.error("carMx updateForSql:",e);
                                            }
                                        }
                                    }
                                }
                            }catch (Exception e){
                                log.error("carMx error:",e);
                            }
                            listMx=null;
                        }catch (Exception e){
                            log.error("补传异常"+JSONObject.toJSONString(s),e);
                        }

                    }
                    listByConsignmentBillMaster=null;
                    end = System.currentTimeMillis();
                    System.out.println(jrpt.getOrganizationcode()+" DataSource:" + dataSource + ";Databasename:" + databasename + ";派车单数据：" + listNum + ";消耗" + (end - begin) + "豪秒。");
                }
            }
        }catch (Exception e){

            log.error("pcmb error:",e);
        }finally {

        }
    }
    @Override
    public void insert_dshk_shanfu(String dataSource, String databasename, String wxpublicnumber, String appid
            ,String CreateTimeBegin,String CreateTimeEnd,String OrganizationCode) {
        String seleclSql;
        try{
                    seleclSql="select (CASE WHEN GiveDate IS NULL THEN '未发放' WHEN GiveType='现金' THEN '已发放'  WHEN FileExportDate IS NULL THEN '已发放' WHEN TransferAccountResult='成功' THEN '转账成功' WHEN TransferAccountResult='失败' THEN '转账失败' ELSE '已导出' END) AS DataStatus,z.FyCloudCode tenant,z.FyCloudPassword tenantPass" +
                            ",a.OrganizationCode,CollectionGoodsValueAccountId,a.ConsignmentBillMasterId,ConsignmentBillNumber,TransportStartDate\n" +
                            " ,CollectionGoodsValue,CollectionGoodsValueDec,DeductionTransportCost,ReturnMoneyId\n" +
                            " ,ReturnMoneyNumber,ReturnMoneyFlag,ReturnMoneyDate,ReturnMoneyCompanyName,ReturnMoneyOperator,GiveFlag\n" +
                            " ,GiveDate,GiveCompanyName,GiveOperator,GiveRemark,ExtraCost,ExceedExtraCost,LoseExtraCost,ExtraCostOverCharge,ExtraCostDecreaseCharge\n" +
                            " ,ShortMessageCharge,AdvancedExtraCost,YearlyPayment,YearlyPaymentCollection,OneCardId,OneCardCode,BankName\n" +
                            " ,AccountHolder,Account,AccountType,ShortMessageMobileTelephone,DoPerson,IdCard,SingleNumber,ExtraCostCountFlag\n" +
                            " ,BatchNumber,FileExportFlag,FileExportDate,FileExportOperator,FileExportCompanyName,TransferAccountDate,TransferAccountOperator\n" +
                            " ,TransferAccountCompanyName,TransferAccountResult,TransferAccountRemark,GiveType,CheckOperator,CheckDate,CheckRemark \n" +
                            " ,CheckCompanyName,RecheckOperator,RecheckDate,RecheckRemark,RecheckCompanyName,TempNotPaymentOperator\n" +
                            " ,TempNotPaymentTime,TempNotPaymentRemark,CanPaymentOperator,CanPaymentTime,CanPaymentRemark,CollectionGoodsValueInc\n" +
                            " ,CollectionGoodsValueDate,CollectionGoodsValueRemark,CollectionGoodsValueCompany,CollectionGoodsValueOperator\n" +
                            " ,SettlementInsuranceCost,0 DataType,GiveDate SysTime " +
                            " ,GoodsNumber,ManualNumber,ConsignmentBillDate,Consignee,ConsigneeMobileTelephone,ConsigneeTelephone,Consignor,ConsignorMobileTelephone, \n" +
                            " ConsignorTelephone,SendCompany,ReceiveCompany,Consi.CollectionGoodsValueType from CollectionGoodsValueAccount as a WITH(NOLOCK) left join (select ConsignmentBillMasterId\n" +
                            ",GoodsNumber,ManualNumber,ConsignmentBillDate,Consignee,ConsigneeMobileTelephone,ConsigneeTelephone,Consignor,ConsignorMobileTelephone, \n" +
                            " ConsignorTelephone,SendCompany,ReceiveCompany,CollectionGoodsValueType from ConsignmentBillMaster WITH(NOLOCK)) Consi on a.ConsignmentBillMasterId=Consi.ConsignmentBillMasterId\n" +
                            "  left join Sys_Company z WITH(NOLOCK) on a.OrganizationCode=z.OrganizationCode  and z.CompanyType='总公司' " +
                            " where  GiveDate>='2020-09-01 00:00:00' AND GiveDate<='2020-12-21 23:59:59' " +
                            " and CollectionGoodsValueType='秒付通' ";
                    List<CollectiongoodsvalueaccountPublic> listByConsignmentBillMaster = jdbcDao.queryListForSql(seleclSql, CollectiongoodsvalueaccountPublic.class);
                   log.info("总代收："+listByConsignmentBillMaster.size());
                    for (CollectiongoodsvalueaccountPublic s : listByConsignmentBillMaster) {
                        try{
                            String  obtainsystime="";
                            if (s.getObtainsystime()!=null){
                                obtainsystime=s.getObtainsystime()+"";
                                if(obtainsystime.length()>19){
                                    obtainsystime=obtainsystime.substring(0,19);
                                }
                            }
                            String  returnmoneydate="";//回款日期
                            if (s.getReturnmoneydate()!=null){
                                returnmoneydate=s.getReturnmoneydate()+"";
                                if(returnmoneydate.length()>19){
                                    returnmoneydate=returnmoneydate.substring(0,19);
                                }
                            }
                            String  givedate="";//支付日期  F6转账日期
                            if (s.getGivedate()!=null){
                                givedate=s.getGivedate()+"";
                                if(givedate.length()>19){
                                    givedate=givedate.substring(0,19);
                                }
                            }
                            String  consignmentbilldate="";
                            if (s.getConsignmentbilldate()!=null){
                                consignmentbilldate=s.getConsignmentbilldate()+"";
                                if(consignmentbilldate.length()>19){
                                    consignmentbilldate=consignmentbilldate.substring(0,19);
                                }
                            }
                            String systime="";
                            if (s.getSystime()!=null){
                                systime=s.getSystime()+"";
                                if(systime.length()>19){
                                    systime=systime.substring(0,19);
                                }
                            }
                            String consignor=s.getConsignor();
                            if (consignor!=null&&consignor.length()!=0){
                                consignor=consignor.replace("'","");
                            }
                            String consignee=s.getConsignee();
                            if (consignee!=null&&consignee.length()!=0){
                                consignee=consignee.replace("'","");
                            }
                            String seSql=" select * from CollectionGoodsValueAccount_Public WITH(NOLOCK) where CollectionGoodsValueAccountId='"+s.getCollectiongoodsvalueaccountid()+"'";
                            List<CollectiongoodsvalueaccountPublic> list = jdbcDao_GoodsTracked.queryListForSql(seSql, CollectiongoodsvalueaccountPublic.class);
                            log.info(s.getCollectiongoodsvalueaccountid()+"业务条数："+list.size());
                            if(list!=null&&list.size()>0){
                                String isnerSql="update  CollectionGoodsValueAccount_Public " +
                                        " set Extracost='"+s.getExtracost()+"' " +
                                        "  ,Shortmessagecharge='"+s.getShortmessagecharge()+"'  "+
                                        " ,Collectiongoodsvaluetype='秒付通',datatype='1',flagnew=''"+
                                        " where CollectionGoodsValueAccountId='"+s.getCollectiongoodsvalueaccountid()+"'";
                                isnerSql=isnerSql.replace("null","");
                                int a= jdbcDao_GoodsTracked.updateForSql(isnerSql);
                                log.info(s.getCollectiongoodsvalueaccountid()+"修改："+a);
                            }else{
                                String isnerSql="insert into CollectionGoodsValueAccount_Public (ExtraCost,organizationcode,collectiongoodsvalueaccountid,consignmentbillmasterid,obtainsystime,consignmentbillnumber,manualnumber,goodsnumber,returnmoneydate,givedate,consignmentbilldate,onecardcode,account,consignee,consigneemobiletelephone,consigneetelephone,consignor,consignormobiletelephone,consignortelephone,accountholder,shortmessagemobiletelephone,givetype,thirdpartycompany,exceedextracost,loseextracost,extracostovercharge,extracostdecreasecharge,collectiongoodsvalue,deductiontransportcost,collectiongoodsvaluedec,settlementinsurancecost,paymentmoney,shortmessagecharge,bankname,traceplatformid,datatype,tenant,tenantpass,systime,flag,trackingno,datastatus) " +
                                        " values ('"+s.getExtracost()+"','"+s.getOrganizationcode()+"','"+s.getCollectiongoodsvalueaccountid()+"','"+s.getConsignmentbillmasterid()+"','"+
                                        obtainsystime+"','"+s.getConsignmentbillnumber()+"','"+s.getManualnumber()+"','"+s.getGoodsnumber()+"','"+
                                        returnmoneydate+"','"+givedate+"','"+consignmentbilldate+"','"+s.getOnecardcode()+"','"
                                        +s.getAccount()+"','"+consignee+"','"+s.getConsigneemobiletelephone()+"','"+s.getConsigneetelephone()
                                        +"','"+consignor+"','"+s.getConsignormobiletelephone()+"','"+s.getConsignortelephone()+"','"+s.getAccountholder()+"','"+s.getShortmessagemobiletelephone()+"','"+s.getGivetype()+"','"+s.getThirdpartycompany()+"','"+s.getExceedextracost()+"','"+s.getLoseextracost()+"','"+s.getExtracostovercharge()+"','"+s.getExtracostdecreasecharge()+"','"+s.getCollectiongoodsvalue()+"','"+s.getDeductiontransportcost()+"','"+s.getCollectiongoodsvaluedec()+"','"+s.getSettlementinsurancecost()+"','"+s.getPaymentmoney()+"','"+s.getShortmessagecharge()+"','"+s.getBankname()+"','"+s.getTraceplatformid()+"','"+s.getDatatype()+"','"+s.getTenant()+"','"+s.getTenantpass()+"','"+
                                        givedate+"','"+s.getFlag()+"','"+s.getTrackingno()+"','"+s.getDatastatus()+"')";
                                isnerSql=isnerSql.replace("null","");

                                int a= jdbcDao_GoodsTracked.updateForSql(isnerSql);
                                log.info(s.getCollectiongoodsvalueaccountid()+"保存："+a);
                            }


                        }catch (Exception e){
                            log.error("代收补抓 error:",e);
                        }

                    }
                    listByConsignmentBillMaster=null;

        }catch (Exception e){
            log.error("dshksave error",e);
        }
    }


    @Override
    public void insert_dshk_jufu(String dataSource, String databasename, String wxpublicnumber, String appid
            ,String CreateTimeBegin,String CreateTimeEnd,String OrganizationCode) {
        String seleclSql;
        try{
            seleclSql=" SELECT " +
                    "(CASE WHEN GiveDate IS NULL THEN '未发放' WHEN GiveType='现金' THEN '已发放'  WHEN FileExportDate IS NULL THEN '已发放' WHEN TransferAccountResult='成功' THEN '转账成功' WHEN TransferAccountResult='失败' THEN '转账失败' ELSE '已导出' END) AS DataStatus,z.FyCloudCode tenant,z.FyCloudPassword tenantPass" +
                    ", a.OrganizationCode,CollectionGoodsValueAccountId,a.ConsignmentBillMasterId,ConsignmentBillNumber,TransportStartDate" +
                    " ,CollectionGoodsValue,CollectionGoodsValueDec,DeductionTransportCost,ReturnMoneyId " +
                    " ,ReturnMoneyNumber,ReturnMoneyFlag,ReturnMoneyDate,ReturnMoneyCompanyName,ReturnMoneyOperator,GiveFlag " +
                    " ,GiveDate,GiveCompanyName,GiveOperator,GiveRemark,ExtraCost,ExceedExtraCost,LoseExtraCost,ExtraCostOverCharge,ExtraCostDecreaseCharge" +
                    " ,ShortMessageCharge,AdvancedExtraCost,YearlyPayment,YearlyPaymentCollection,OneCardId,OneCardCode,BankName " +
                    " ,AccountHolder,Account,AccountType,ShortMessageMobileTelephone,DoPerson,IdCard,SingleNumber,ExtraCostCountFlag " +
                    " ,BatchNumber,FileExportFlag,FileExportDate,FileExportOperator,FileExportCompanyName,TransferAccountDate,TransferAccountOperator " +
                    " ,TransferAccountCompanyName,'全拒付' AS TransferAccountResult,TransferAccountRemark,GiveType,a.CheckOperator,a.CheckDate,a.CheckRemark " +
                    " ,a.CheckCompanyName,a.RecheckOperator,a.RecheckDate,a.RecheckRemark,a.RecheckCompanyName,TempNotPaymentOperator " +
                    " ,TempNotPaymentTime,TempNotPaymentRemark,CanPaymentOperator,CanPaymentTime,CanPaymentRemark,CollectionGoodsValueInc " +
                    " ,CollectionGoodsValueDate,CollectionGoodsValueRemark,CollectionGoodsValueCompany,CollectionGoodsValueOperator " +
                    " ,SettlementInsuranceCost,0 as DataType,a.createTime as SysTime " +
                    " ,GoodsNumber,ManualNumber,ConsignmentBillDate,Consignee,ConsigneeMobileTelephone,ConsigneeTelephone,Consignor,ConsignorMobileTelephone," +
                    " ConsignorTelephone,SendCompany,ReceiveCompany,Consi.CollectionGoodsValueType from CollectionGoodsValueAccount as a WITH(NOLOCK)" +
                    " left join (select ConsignmentBillMasterId,GoodsNumber,ManualNumber,ConsignmentBillDate,Consignee,ConsigneeMobileTelephone,ConsigneeTelephone,Consignor,ConsignorMobileTelephone," +
                    " ConsignorTelephone,SendCompany,ReceiveCompany,CollectionGoodsValueType from ConsignmentBillMaster WITH(NOLOCK)) Consi on a.ConsignmentBillMasterId=Consi.ConsignmentBillMasterId" +
                    "  LEFT JOIN BillOtherInfo b ON a.ConsignmentBillMasterId=b.BillOtherInfoId " +
                    "left join Sys_Company z WITH(NOLOCK) on a.OrganizationCode=z.OrganizationCode  and z.CompanyType='总公司' " +
                    " WHERE   CollectionGoodsValueDec=CollectionGoodsValue AND a.createTime>='"+CreateTimeBegin+"' and AND a.createTime>='"+CreateTimeEnd+"'";
            List<CollectiongoodsvalueaccountPublic> listByConsignmentBillMaster = jdbcDao.queryListForSql(seleclSql, CollectiongoodsvalueaccountPublic.class);
            log.info("总代收："+listByConsignmentBillMaster.size());
            for (CollectiongoodsvalueaccountPublic s : listByConsignmentBillMaster) {
                try{
                    String  obtainsystime="";
                    if (s.getObtainsystime()!=null){
                        obtainsystime=s.getObtainsystime()+"";
                        if(obtainsystime.length()>19){
                            obtainsystime=obtainsystime.substring(0,19);
                        }
                    }
                    String  returnmoneydate="";//回款日期
                    if (s.getReturnmoneydate()!=null){
                        returnmoneydate=s.getReturnmoneydate()+"";
                        if(returnmoneydate.length()>19){
                            returnmoneydate=returnmoneydate.substring(0,19);
                        }
                    }
                    String  givedate="";//支付日期  F6转账日期
                    if (s.getGivedate()!=null){
                        givedate=s.getGivedate()+"";
                        if(givedate.length()>19){
                            givedate=givedate.substring(0,19);
                        }
                    }
                    String  consignmentbilldate="";
                    if (s.getConsignmentbilldate()!=null){
                        consignmentbilldate=s.getConsignmentbilldate()+"";
                        if(consignmentbilldate.length()>19){
                            consignmentbilldate=consignmentbilldate.substring(0,19);
                        }
                    }
                    String systime="";
                    if (s.getSystime()!=null){
                        systime=s.getSystime()+"";
                        if(systime.length()>19){
                            systime=systime.substring(0,19);
                        }
                    }
                    String consignor=s.getConsignor();
                    if (consignor!=null&&consignor.length()!=0){
                        consignor=consignor.replace("'","");
                    }
                    String consignee=s.getConsignee();
                    if (consignee!=null&&consignee.length()!=0){
                        consignee=consignee.replace("'","");
                    }
                    String seSql=" select * from CollectionGoodsValueAccount_Public WITH(NOLOCK) where CollectionGoodsValueAccountId='"+s.getCollectiongoodsvalueaccountid()+"'";
                    List<CollectiongoodsvalueaccountPublic> list = jdbcDao_GoodsTracked.queryListForSql(seSql, CollectiongoodsvalueaccountPublic.class);
                    log.info(s.getCollectiongoodsvalueaccountid()+"业务条数："+list.size());
                    if(list!=null&&list.size()>0){

                        log.info(s.getCollectiongoodsvalueaccountid()+" 已存在全拒付");
                    }else{
                        String isnerSql="insert into CollectionGoodsValueAccount_Public (TransferAccountResult,ExtraCost,organizationcode,collectiongoodsvalueaccountid,consignmentbillmasterid,obtainsystime,consignmentbillnumber,manualnumber,goodsnumber,returnmoneydate,givedate,consignmentbilldate,onecardcode,account,consignee,consigneemobiletelephone,consigneetelephone,consignor,consignormobiletelephone,consignortelephone,accountholder,shortmessagemobiletelephone,givetype,thirdpartycompany,exceedextracost,loseextracost,extracostovercharge,extracostdecreasecharge,collectiongoodsvalue,deductiontransportcost,collectiongoodsvaluedec,settlementinsurancecost,paymentmoney,shortmessagecharge,bankname,traceplatformid,datatype,tenant,tenantpass,systime,flag,trackingno,datastatus) " +
                                " values ('"+s.getTransferaccountresult()+"','"+s.getExtracost()+"','"+s.getOrganizationcode()+"','"+s.getCollectiongoodsvalueaccountid()+"','"+s.getConsignmentbillmasterid()+"','"+
                                obtainsystime+"','"+s.getConsignmentbillnumber()+"','"+s.getManualnumber()+"','"+s.getGoodsnumber()+"','"+
                                returnmoneydate+"','"+givedate+"','"+consignmentbilldate+"','"+s.getOnecardcode()+"','"
                                +s.getAccount()+"','"+consignee+"','"+s.getConsigneemobiletelephone()+"','"+s.getConsigneetelephone()
                                +"','"+consignor+"','"+s.getConsignormobiletelephone()+"','"+s.getConsignortelephone()+"','"+s.getAccountholder()+"','"+s.getShortmessagemobiletelephone()+"','"+s.getGivetype()+"','"+s.getThirdpartycompany()+"','"+s.getExceedextracost()+"','"+s.getLoseextracost()+"','"+s.getExtracostovercharge()+"','"+s.getExtracostdecreasecharge()+"','"+s.getCollectiongoodsvalue()+"','"+s.getDeductiontransportcost()+"','"+s.getCollectiongoodsvaluedec()+"','"+s.getSettlementinsurancecost()+"','"+s.getPaymentmoney()+"','"+s.getShortmessagecharge()+"','"+s.getBankname()+"','"+s.getTraceplatformid()+"','"+s.getDatatype()+"','"+s.getTenant()+"','"+s.getTenantpass()+"','"+
                                givedate+"','"+s.getFlag()+"','"+s.getTrackingno()+"','"+s.getDatastatus()+"')";
                        isnerSql=isnerSql.replace("null","");

                        int a= jdbcDao_GoodsTracked.updateForSql(isnerSql);
                        log.info(s.getCollectiongoodsvalueaccountid()+"保存："+a);
                    }


                }catch (Exception e){
                    log.error("代收补抓 error:",e);
                }

            }
            listByConsignmentBillMaster=null;

        }catch (Exception e){
            log.error("dshksave error",e);
        }
    }
    @Override
    public void insert_dshk_buchuan(String dataSource, String databasename, String wxpublicnumber, String appid
            ,String CreateTimeBegin,String CreateTimeEnd,String OrganizationCode) {
        if (wxpublicnumber == null) {
            wxpublicnumber = "";
        }
        if (appid == null) {
            appid = "";
        }
        String sqlArray0 = "";
        List<GoodsTrack> listByDelete = new ArrayList<GoodsTrack>();
        Long begin;
        String seleclSql;
        Long end;
        begin = System.currentTimeMillis();
//        seleclSql = " select TOP  "+(j * max)+"  CollectionGoodsValueAccountId, t.*,c.FyCloudCode tenant,c.FyCloudPassword tenantPass ," +
//                "(case when (IsNull(CollectionGoodsValue,0)-IsNull(CollectionGoodsValueDec,0) - IsNull(DeductionTransportCost,0)- IsNull(CollectionGoodsValueInc,0))<0 then 0 else (IsNull(CollectionGoodsValue,0)-IsNull(CollectionGoodsValueDec,0) - IsNull(DeductionTransportCost,0)- IsNull(CollectionGoodsValueInc,0)) End -IsNull(SettlementInsuranceCost,0)-IsNull(ExtraCost,0)-IsNull(ExceedExtraCost,0)-IsNull(LoseExtraCost,0)-IsNull(ShortMessageCharge,0)-IsNull(ExtraCostOverCharge,0)+IsNull(ExtraCostDecreaseCharge,0)) paymentmoney "+
//                "  from CollectionGoodsValueAccount_Temp t WITH(NOLOCK)  " +
//                "  left join Sys_Company c on t.OrganizationCode=c.OrganizationCode AND t.sendCompany=c.CompanyName "+
//                "  where t.SysTime<='" + datetime + "'";
//        List<CollectiongoodsvalueaccountPublic> listByConsignmentBillMaster = jdbcDao.queryListForSql(seleclSql, CollectiongoodsvalueaccountPublic.class);

        try{
            List<Jrpt> jrpts = jrptService.select();
            for (Jrpt jrpt : jrpts) {
                if(jrpt!=null&&jrpt.getOrganizationcode()!=null&&jrpt.getOrganizationcode().length()!=0){
                    OrganizationCode=jrpt.getOrganizationcode();
                    seleclSql=" select (CASE WHEN GiveDate IS NULL THEN '未发放' WHEN GiveType='现金' THEN '已发放'  WHEN FileExportDate IS NULL THEN '已发放' WHEN TransferAccountResult='成功' THEN '转账成功' WHEN TransferAccountResult='失败' THEN '转账失败' ELSE '已导出' END) AS DataStatus,z.FyCloudCode tenant,z.FyCloudPassword tenantPass," +
                            " a.OrganizationCode OrganizationCode,CollectionGoodsValueAccountId,a.ConsignmentBillMasterId,ConsignmentBillNumber,TransportStartDate \n" +
                            "      ,CollectionGoodsValue,CollectionGoodsValueDec,DeductionTransportCost,ReturnMoneyId \n" +
                            "      ,ReturnMoneyNumber,ReturnMoneyFlag,ReturnMoneyDate,ReturnMoneyCompanyName,ReturnMoneyOperator,GiveFlag \n" +
                            "      ,GiveDate,GiveCompanyName,GiveOperator,GiveRemark,ExtraCost,ExceedExtraCost,LoseExtraCost,ExtraCostOverCharge,ExtraCostDecreaseCharge \n" +
                            "      ,ShortMessageCharge,AdvancedExtraCost,YearlyPayment,YearlyPaymentCollection,OneCardId,OneCardCode,BankName \n" +
                            "      ,AccountHolder,Account,AccountType,ShortMessageMobileTelephone,DoPerson,IdCard,SingleNumber,ExtraCostCountFlag \n" +
                            "      ,BatchNumber,FileExportFlag,FileExportDate,FileExportOperator,FileExportCompanyName,TransferAccountDate,TransferAccountOperator \n" +
                            "      ,TransferAccountCompanyName,TransferAccountResult,TransferAccountRemark,GiveType,CheckOperator,CheckDate,CheckRemark  \n" +
                            "      ,CheckCompanyName,RecheckOperator,RecheckDate,RecheckRemark,RecheckCompanyName,TempNotPaymentOperator \n" +
                            "      ,TempNotPaymentTime,TempNotPaymentRemark,CanPaymentOperator,CanPaymentTime,CanPaymentRemark,CollectionGoodsValueInc \n" +
                            "      ,CollectionGoodsValueDate,CollectionGoodsValueRemark,CollectionGoodsValueCompany,CollectionGoodsValueOperator \n" +
                            "      ,ISNULL(SettlementInsuranceCost,0)as SettlementInsuranceCost,0 DataType,GETDATE() SysTime\n" +
                            "      ,GoodsNumber,ManualNumber,ConsignmentBillDate,Consignee,ConsigneeMobileTelephone,ConsigneeTelephone,Consignor,ConsignorMobileTelephone,\n" +
                            "      ConsignorTelephone,SendCompany,ReceiveCompany from CollectionGoodsValueAccount as a WITH(NOLOCK) left join (select ConsignmentBillMasterId \n" +
                            "     ,GoodsNumber,ManualNumber,ConsignmentBillDate,Consignee,ConsigneeMobileTelephone,ConsigneeTelephone,Consignor,ConsignorMobileTelephone,\n" +
                            "           ConsignorTelephone,SendCompany,ReceiveCompany from ConsignmentBillMaster WITH(NOLOCK)) Consi on a.ConsignmentBillMasterId=Consi.ConsignmentBillMasterId\n" +
                            " left join Sys_Company c WITH(NOLOCK) on a.OrganizationCode=c.OrganizationCode AND Consi.sendCompany=c.CompanyName "+
                            "      left join Sys_Company z WITH(NOLOCK) on a.OrganizationCode=z.OrganizationCode and z.OrganizationCode='"+OrganizationCode+"' and z.CompanyType='总公司'"+
                            "      where GiveDate>='"+CreateTimeBegin+"' AND GiveDate<='"+CreateTimeEnd+"' AND a.OrganizationCode='"+OrganizationCode+"'";
                    List<CollectiongoodsvalueaccountPublic> listByConsignmentBillMaster = jdbcDao.queryListForSql(seleclSql, CollectiongoodsvalueaccountPublic.class);
                    String numSql="";
                    int num=0;
                    for (CollectiongoodsvalueaccountPublic s : listByConsignmentBillMaster) {
                        try{
                            String  obtainsystime="";
                            if (s.getObtainsystime()!=null){
                                obtainsystime=s.getObtainsystime()+"";
                                if(obtainsystime.length()>19){
                                    obtainsystime=obtainsystime.substring(0,19);
                                }
                            }
                            String  returnmoneydate="";//回款日期
                            if (s.getReturnmoneydate()!=null){
                                returnmoneydate=s.getReturnmoneydate()+"";
                                if(returnmoneydate.length()>19){
                                    returnmoneydate=returnmoneydate.substring(0,19);
                                }
                            }
                            String  givedate="";//支付日期  F6转账日期
                            if (s.getGivedate()!=null){
                                givedate=s.getGivedate()+"";
                                if(givedate.length()>19){
                                    givedate=givedate.substring(0,19);
                                }
                            }
                            String  consignmentbilldate="";
                            if (s.getConsignmentbilldate()!=null){
                                consignmentbilldate=s.getConsignmentbilldate()+"";
                                if(consignmentbilldate.length()>19){
                                    consignmentbilldate=consignmentbilldate.substring(0,19);
                                }
                            }
                            String systime="";
                            if (s.getSystime()!=null){
                                systime=s.getSystime()+"";
                                if(systime.length()>19){
                                    systime=systime.substring(0,19);
                                }
                            }
                            String consignor=s.getConsignor();
                            if (consignor!=null&&consignor.length()!=0){
                                consignor=consignor.replace("'","");
                            }
                            String consignee=s.getConsignee();
                            if (consignee!=null&&consignee.length()!=0){
                                consignee=consignee.replace("'","");
                            }

                            String isnerSql="insert into CollectionGoodsValueAccount_Public (ExtraCost,organizationcode,collectiongoodsvalueaccountid,consignmentbillmasterid,obtainsystime,consignmentbillnumber,manualnumber,goodsnumber,returnmoneydate,givedate,consignmentbilldate,onecardcode,account,consignee,consigneemobiletelephone,consigneetelephone,consignor,consignormobiletelephone,consignortelephone,accountholder,shortmessagemobiletelephone,givetype,thirdpartycompany,exceedextracost,loseextracost,extracostovercharge,extracostdecreasecharge,collectiongoodsvalue,deductiontransportcost,collectiongoodsvaluedec,settlementinsurancecost,paymentmoney,shortmessagecharge,bankname,traceplatformid,datatype,tenant,tenantpass,systime,flag,trackingno,datastatus) " +
                                    " values ('"+s.getExtracost()+"','"+s.getOrganizationcode()+"','"+s.getCollectiongoodsvalueaccountid()+"','"+s.getConsignmentbillmasterid()+"','"+
                                    obtainsystime+"','"+s.getConsignmentbillnumber()+"','"+s.getManualnumber()+"','"+s.getGoodsnumber()+"','"+
                                    returnmoneydate+"','"+givedate+"','"+consignmentbilldate+"','"+s.getOnecardcode()+"','"
                                    +s.getAccount()+"','"+consignee+"','"+s.getConsigneemobiletelephone()+"','"+s.getConsigneetelephone()
                                    +"','"+consignor+"','"+s.getConsignormobiletelephone()+"','"+s.getConsignortelephone()+"','"+s.getAccountholder()+"','"+s.getShortmessagemobiletelephone()+"','"+s.getGivetype()+"','"+s.getThirdpartycompany()+"','"+s.getExceedextracost()+"','"+s.getLoseextracost()+"','"+s.getExtracostovercharge()+"','"+s.getExtracostdecreasecharge()+"','"+s.getCollectiongoodsvalue()+"','"+s.getDeductiontransportcost()+"','"+s.getCollectiongoodsvaluedec()+"','"+s.getSettlementinsurancecost()+"','"+s.getPaymentmoney()+"','"+s.getShortmessagecharge()+"','"+s.getBankname()+"','"+s.getTraceplatformid()+"','"+s.getDatatype()+"','"+s.getTenant()+"','"+s.getTenantpass()+"','"+
                                    givedate+"','"+s.getFlag()+"','"+s.getTrackingno()+"','"+s.getDatastatus()+"')";
                            isnerSql=isnerSql.replace("null","");
                            int a= jdbcDao_GoodsTracked.updateForSql(isnerSql);
//                            ResultModel reModel= jrptExecutor.uploadCollection(SystemConstants.CAR_URL,car);
//                            if (100==reModel.getCode()){
//                                num=num+1;
//                            }else{
////                                car = (CollectiongoodsvalueaccountPublic)killNull(car);
//                                car.setTrackingno("补传失败"+reModel.getMessage());
//                                car.setFlag("0");
//                                jdbcDao_GoodsTracked.insert(car);
//                            }
                        }catch (Exception e){
                            log.error("代收补抓 error:",e);
                        }

                    }
                    end = System.currentTimeMillis();
                    log.info("CreateTimeBegin:"+CreateTimeBegin+" CreateTimeEnd:"+CreateTimeEnd+" OrganizationCode:"+OrganizationCode+" DataSource:" + dataSource + ";Databasename:" + databasename + ";代收数据：" + listByConsignmentBillMaster.size() + ";消耗" + (end - begin) + "豪秒。");
                    listByConsignmentBillMaster=null;
                }
            }

        }catch (Exception e){
            log.error("dshksave error",e);
        }
    }
    @Override
    public void insert_order_buchuan(String dataSource, String databasename, String wxpublicnumber, String appid
            ,String CreateTimeBegin,String CreateTimeEnd,String OrganizationCode) {
        if (wxpublicnumber == null) {
            wxpublicnumber = "";
        }
        if (appid == null) {
            appid = "";
        }
        String sqlArray0 = "";
        List<GoodsTrack> listByDelete = new ArrayList<GoodsTrack>();
        Long begin;
        String seleclSql;
        Long end;
        begin = System.currentTimeMillis();

        try{ String tsql=" Isnull(z.CompanyName, '') as headquartersname,Isnull(a.CreateOperator, '') CreateOperator,Isnull(z.CompanyPhoneNumber, '') headquarterphone" +
               ",'"+databasename+"'as databasename "+
                ",Isnull(b.FyCloudCode,'') consignorCompanySende, " +
                "Isnull(c.FyCloudCode,'') consigneeCompanySenderCode," +
                "Isnull(b.Longitude,'') ConsignmentLongitude," +
                "Isnull(b.Latitude,'') ConsignmentLatitude," +
                "Isnull(c.Longitude,'') ArrivalLongitude," +
                "Isnull(c.Latitude,'') ArrivalLatitude," +
//                "CONVERT(varchar(200),a.SendLongitude) SendLongitude," +
//                "CONVERT(varchar(200),a.SendLatitude) SendLatitude," +
//                "a.PickAddress PickAddress," +
//                "CONVERT(varchar(200),a.ReceiveLongitude) ReceiveLongitude," +
//                " CONVERT(varchar(200),a.ReceiveLatitude) ReceiveLatitude," +
                "Isnull(z.FyCloudCode,'') Headquarterscode," +
                "Isnull(z.FyCloudPassword,'') headquarterspassword," +
                "Isnull(c.FyCloudCode,'') arrivalcode," +
                "Isnull(c.FyCloudPassword,'') arrivalpassword," +
                "Isnull(b.FyCloudCode ,'') consignmentcode," +
                "Isnull(b.FyCloudPassword,'') consignmentpassword,";
            List<Jrpt> jrpts = jrptService.select();
//            for (Jrpt jrpt : jrpts) {
            int i=0;
                while(true){
                    i++;
                    seleclSql=" select * from( select "+tsql+"Row_Number() OVER(ORDER BY a.ConsignmentBillMasterId) AS rowNum,a.OrganizationCode,Isnull(ConsignmentBillMasterId,'')ConsignmentBillMasterId,Isnull(ConsignmentBillNumber,'')ConsignmentBillNumber, \n" +
                            "       GoodsNumber,ManualNumber, ConsignmentBillDate,PlaceOfLoading" +
                            ",SendCompany,ReceiveCompany,UnloadPlace,ConsignorCompanyCode" +
                            ", ConsignorCompany, Consignor, ConsignorMobileTelephone,ConsignorTelephone" +
                            ", ConsignorAddress,ConsigneeCompanyCode,ConsigneeCompany,Consignee" +
                            ",ConsigneeMobileTelephone,ConsigneeTelephone,ConsigneeAddress,OneCardCode" +
                            ",BankName,AccountHolder,Account,PaymentMethod" +
                            ",GoodsPickupMethod,ConsignmentBillRemark,GoodsName,GoodsPack" +
                            ", IsReceipt,ReceiptNumber,ReceiptCount,ReceiptRemark" +
                            ",TotalNumberOfPackages,TotalWeight,TotalVolume,TotalTransportCost" +
                            ", CollectionGoodsValue,AdvanceGoodsValue, AdvanceTransportCost ,a.createTime SysTime " +
                            ", Consignoridcard,Consigneeidcard,ISNULL(b.Longitude,'0')SendLongitude" +
                            ",ISNULL(b.Latitude,'0')SendLatitude,'' PickAddress,ISNULL(c.Longitude,'0')ReceiveLongitude," +
                            "     ISNULL(c.Latitude,'0')ReceiveLatitude, " +
                            "      convert(varchar(20),convert(decimal(18,0),CASE WHEN OfflineUpload='App' THEN 1 WHEN  OfflineUpload='在线下单' THEN 2 ELSE 0 END))  CreateType,Isnull(a.PlatformNumber, '') PlatformNumber" +
                            ",ArrivalAllPayCost,InsuranceAmount,InsuranceCost,a.CreateTime,TransferCost,SendCost,PickupCost,PackCost,OtherCost " +
                            "       from ConsignmentBillMaster as a WITH(NOLOCK) " +
                            "       left join (SELECT * FROM Sys_Company WITH(NOLOCK) ) as b on  a.OrganizationCode=b.OrganizationCode and  a.SendCompany=b.CompanyName\n" +
                            "       left join (SELECT * FROM Sys_Company WITH(NOLOCK) ) as c on  a.OrganizationCode=c.OrganizationCode and a.ReceiveCompany=c.CompanyName\n" +
                            "    left join Sys_Company z WITH(NOLOCK) on a.OrganizationCode=z.OrganizationCode and z.CompanyType='总公司'"+
                            "       where ConsignmentBillDate>='"+CreateTimeBegin+"' AND ConsignmentBillDate<='"+CreateTimeEnd+"') temp " +
                            " where rowNum BETWEEN "+((i-1)*10000+1)+"  AND "+i*10000+" " ;
                    List<GoodstrackedRecordTopPublicF6> listByConsignmentBillMaster = jdbcDao.queryListForSql(seleclSql, GoodstrackedRecordTopPublicF6.class);
                    if (listByConsignmentBillMaster==null||listByConsignmentBillMaster.size()==0){
                        break;
                    }
                    String numSql="";
                    int num=0;
                    int pointsDataLimit = 500;//限制条数

                    Integer size = listByConsignmentBillMaster.size();
                    log.info(i+"库："+databasename+"sql:"+seleclSql);
                    log.info(i+"库："+databasename+"总数:"+listByConsignmentBillMaster.size());
                    if(pointsDataLimit<size){
                        int part = size/pointsDataLimit;//分批数
                        ExecutorService pool = Executors.newFixedThreadPool(part+1);

                        for (int c = 0; c < part; c++) {
                            List<GoodstrackedRecordTopPublicF6> listPage = listByConsignmentBillMaster.subList(0, pointsDataLimit);
                            try{
                                //剔除
                                JSONArray a = (JSONArray) JSONObject.toJSON(listPage);
                                GoodsOrderCallable callable = new GoodsOrderCallable( "top123",a.toString());
                                Future fContent = pool.submit(callable);
                                a=null;
                                listPage=null;
                            }catch (Exception e){
                                log.error("线程异常",e);

                            }
                            listByConsignmentBillMaster.subList(0, pointsDataLimit).clear();

                        }
                        pool.shutdown();
                        if(!listByConsignmentBillMaster.isEmpty()){
                            try{
                                for (GoodstrackedRecordTopPublicF6 s : listByConsignmentBillMaster) {
                                    try{
                                        String  insertSql = "insert into GoodsTracked_Record_Top_Public( " +
                                                "headquartersname,CreateOperator,CreateTime,headquarterphone,databasename,consignorCompanySende,consigneeCompanySenderCode,createType"+
                                                ",ConsignmentLongitude,ConsignmentLatitude,ArrivalLongitude,ArrivalLatitude," +
                                                "SendLongitude,SendLatitude,PickAddress,PlatformNumber,ReceiveLongitude,ReceiveLatitude," +
                                                "Headquarterscode,headquarterspassword,arrivalcode,arrivalpassword,consignmentcode ,consignmentpassword," +
                                                "  OrganizationCode,ConsignmentBillMasterId,ConsignmentBillNumber,GoodsNumber,ManualNumber,ConsignmentBillDate,PlaceOfLoading,SendCompany,ReceiveCompany,UnloadPlace,ConsignorCompanyCode,ConsignorCompany,Consignor,ConsignorMobileTelephone,ConsignorTelephone,ConsignorAddress,ConsigneeCompanyCode,ConsigneeCompany, Consignee,ConsigneeMobileTelephone" +
                                                "  ,ConsigneeTelephone, ConsigneeAddress,Consignoridcard,Consigneeidcard,OneCardCode,BankName,AccountHolder,Account,PaymentMethod,GoodsPickupMethod,ConsignmentBillRemark,GoodsName, GoodsPack,IsReceipt,ReceiptNumber,ReceiptCount,ReceiptRemark,TotalNumberOfPackages," +
                                                " TotalWeight,ArrivalAllPayCost,InsuranceAmount,InsuranceCost, TotalVolume," +
                                                "TransferCost,SendCost,PickupCost,PackCost,OtherCost,TotalTransportCost, CollectionGoodsValue,AdvanceGoodsValue,AdvanceTransportCost,DataType,SysTime) " +
                                                " values ";
                                        insertSql=insertSql+"('"+s.getHeadquartersname()+"','"+s.getCreateoperator()+"','"+s.getCreatetime()+"','"+s.getHeadquarterphone()+"','"+s.getDatabasename()+"','"+s.getConsignorcompanysende()
                                                +"','"+s.getConsigneecompanysendercode()+"','"+s.getCreatetype()+"','"+s.getConsignmentlongitude()+"','"+s.getConsignmentlatitude()+"','"+
                                                s.getArrivallongitude()+"','"+s.getArrivallatitude()+"','"+s.getSendlongitude()+"','"+s.getSendlatitude()+"','"
                                                +s.getPickaddress()+"','"+s.getPlatformnumber()+"','"+s.getReceivelongitude()+"','"+s.getReceivelatitude()+"','"+s.getHeadquarterscode()
                                                +"','"+s.getHeadquarterspassword()+"','"+s.getArrivalcode()+"','"+s.getArrivalpassword()+"','"+s.getConsignmentcode ()+"','"
                                                +s.getConsignmentpassword()+"','"+s.getOrganizationcode()+"','"+s.getConsignmentbillmasterid()+"','"+s.getConsignmentbillnumber()
                                                +"','"+s.getGoodsnumber()+"','"+s.getManualnumber()+"','"+s.getConsignmentbilldate()+"','"+s.getPlaceofloading()+"','"+s.getSendcompany()
                                                +"','"+s.getReceivecompany()+"','"+s.getUnloadplace()+"','"+s.getConsignorcompanycode()+"','"+s.getConsignorcompany()+"','"+s.getConsignor()
                                                +"','"+s.getConsignormobiletelephone()+"','"+s.getConsignortelephone()+"','"+s.getConsignoraddress()+"','"+s.getConsigneecompanycode()+"','"
                                                +s.getConsigneecompany()+"','"+s.getConsignee()+"','"+s.getConsigneemobiletelephone  ()+"','"+s.getConsigneetelephone()+"','"+s.getConsigneeaddress()+"','"+s.getConsignoridcard()+"','"+s.getConsigneeidcard()+"','"+s.getOnecardcode()+"','"+s.getBankname()+"','"+s.getAccountholder()+"','"+s.getAccount()+"','"+s.getPaymentmethod()+"','"+s.getGoodspickupmethod()+"','"+s.getConsignmentbillremark()+"','"+s.getGoodsname()+"','"+s.getGoodspack()+"','"+s.getIsreceipt()+"','"+s.getReceiptnumber()+"','"+s.getReceiptcount()+"','"+s.getReceiptremark()+"','"+s.getTotalnumberofpackages()+"','"+s.getTotalweight()+"','"+s.getArrivalallpaycost()+"','"+s.getInsuranceamount()+"','"+s.getInsurancecost()+"','"+s.getTotalvolume()+"','"+s.getTransfercost()+"','"+s.getSendcost()+"','"+s.getPickupcost()+"','"+s.getPackcost()+"','"+s.getOthercost()+"','"+s.getTotaltransportcost()+"','"+s.getCollectiongoodsvalue()+"','"+s.getAdvancegoodsvalue()+"','"
                                                +s.getAdvancetransportcost()+"','0','"+s.getSystime()+"')";
                                        insertSql=insertSql.replace("null","");
                                        jdbcDao_GoodsTracked.updateForSql(insertSql);
                                    }catch (Exception e){
                                        log.error("订单1补抓 error:",e);

                                    }
                                }
                            }catch (Exception e){
                                log.error("线程异常2",e);
                            }
                        }
                    }else{
                        for (GoodstrackedRecordTopPublicF6 s : listByConsignmentBillMaster) {
                            try{
                                String  insertSql = "insert into GoodsTracked_Record_Top_Public( " +
                                        "headquartersname,CreateOperator,CreateTime,headquarterphone,databasename,consignorCompanySende,consigneeCompanySenderCode,createType"+
                                        ",ConsignmentLongitude,ConsignmentLatitude,ArrivalLongitude,ArrivalLatitude," +
                                        "SendLongitude,SendLatitude,PickAddress,PlatformNumber,ReceiveLongitude,ReceiveLatitude," +
                                        "Headquarterscode,headquarterspassword,arrivalcode,arrivalpassword,consignmentcode ,consignmentpassword," +
                                        "  OrganizationCode,ConsignmentBillMasterId,ConsignmentBillNumber,GoodsNumber,ManualNumber,ConsignmentBillDate,PlaceOfLoading,SendCompany,ReceiveCompany,UnloadPlace,ConsignorCompanyCode,ConsignorCompany,Consignor,ConsignorMobileTelephone,ConsignorTelephone,ConsignorAddress,ConsigneeCompanyCode,ConsigneeCompany, Consignee,ConsigneeMobileTelephone" +
                                        "  ,ConsigneeTelephone, ConsigneeAddress,Consignoridcard,Consigneeidcard,OneCardCode,BankName,AccountHolder,Account,PaymentMethod,GoodsPickupMethod,ConsignmentBillRemark,GoodsName, GoodsPack,IsReceipt,ReceiptNumber,ReceiptCount,ReceiptRemark,TotalNumberOfPackages," +
                                        " TotalWeight,ArrivalAllPayCost,InsuranceAmount,InsuranceCost, TotalVolume," +
                                        "TransferCost,SendCost,PickupCost,PackCost,OtherCost,TotalTransportCost, CollectionGoodsValue,AdvanceGoodsValue,AdvanceTransportCost,DataType,SysTime) " +
                                        " values ";
                                insertSql=insertSql+"('"+s.getHeadquartersname()+"','"+s.getCreateoperator()+"','"+s.getCreatetime()+"','"+s.getHeadquarterphone()+"','"+s.getDatabasename()+"','"+s.getConsignorcompanysende()
                                        +"','"+s.getConsigneecompanysendercode()+"','"+s.getCreatetype()+"','"+s.getConsignmentlongitude()+"','"+s.getConsignmentlatitude()+"','"+
                                        s.getArrivallongitude()+"','"+s.getArrivallatitude()+"','"+s.getSendlongitude()+"','"+s.getSendlatitude()+"','"
                                        +s.getPickaddress()+"','"+s.getPlatformnumber()+"','"+s.getReceivelongitude()+"','"+s.getReceivelatitude()+"','"+s.getHeadquarterscode()
                                        +"','"+s.getHeadquarterspassword()+"','"+s.getArrivalcode()+"','"+s.getArrivalpassword()+"','"+s.getConsignmentcode ()+"','"
                                        +s.getConsignmentpassword()+"','"+s.getOrganizationcode()+"','"+s.getConsignmentbillmasterid()+"','"+s.getConsignmentbillnumber()
                                        +"','"+s.getGoodsnumber()+"','"+s.getManualnumber()+"','"+s.getConsignmentbilldate()+"','"+s.getPlaceofloading()+"','"+s.getSendcompany()
                                        +"','"+s.getReceivecompany()+"','"+s.getUnloadplace()+"','"+s.getConsignorcompanycode()+"','"+s.getConsignorcompany()+"','"+s.getConsignor()
                                        +"','"+s.getConsignormobiletelephone()+"','"+s.getConsignortelephone()+"','"+s.getConsignoraddress()+"','"+s.getConsigneecompanycode()+"','"
                                        +s.getConsigneecompany()+"','"+s.getConsignee()+"','"+s.getConsigneemobiletelephone  ()+"','"+s.getConsigneetelephone()+"','"+s.getConsigneeaddress()+"','"+s.getConsignoridcard()+"','"+s.getConsigneeidcard()+"','"+s.getOnecardcode()+"','"+s.getBankname()+"','"+s.getAccountholder()+"','"+s.getAccount()+"','"+s.getPaymentmethod()+"','"+s.getGoodspickupmethod()+"','"+s.getConsignmentbillremark()+"','"+s.getGoodsname()+"','"+s.getGoodspack()+"','"+s.getIsreceipt()+"','"+s.getReceiptnumber()+"','"+s.getReceiptcount()+"','"+s.getReceiptremark()+"','"+s.getTotalnumberofpackages()+"','"+s.getTotalweight()+"','"+s.getArrivalallpaycost()+"','"+s.getInsuranceamount()+"','"+s.getInsurancecost()+"','"+s.getTotalvolume()+"','"+s.getTransfercost()+"','"+s.getSendcost()+"','"+s.getPickupcost()+"','"+s.getPackcost()+"','"+s.getOthercost()+"','"+s.getTotaltransportcost()+"','"+s.getCollectiongoodsvalue()+"','"+s.getAdvancegoodsvalue()+"','"
                                        +s.getAdvancetransportcost()+"','0','"+s.getSystime()+"')";
                                insertSql=insertSql.replace("null","");
                                jdbcDao_GoodsTracked.updateForSql(insertSql);
                            }catch (Exception e){
                                log.error("订单2补抓 error:",e);

                            }
                        }
                    }
                    end = System.currentTimeMillis();
                    log.info("CreateTimeBegin:"+CreateTimeBegin+" CreateTimeEnd:"+CreateTimeEnd+" OrganizationCode:"+OrganizationCode+" DataSource:" + dataSource + ";Databasename:" + databasename + ";订单：" + listByConsignmentBillMaster.size() + ";消耗" + (end - begin) + "豪秒。");
                    listByConsignmentBillMaster=null;

                }
//            }
        }catch (Exception e){
            log.error(" order error:",e);
        }
    }


    @Override
    public void insert_order_jufu(String dataSource, String databasename, String wxpublicnumber, String appid
            ,String CreateTimeBegin,String CreateTimeEnd,String OrganizationCode) {
        if (wxpublicnumber == null) {
            wxpublicnumber = "";
        }
        if (appid == null) {
            appid = "";
        }
        String sqlArray0 = "";
        List<GoodsTrack> listByDelete = new ArrayList<GoodsTrack>();
        Long begin;
        String seleclSql;
        Long end;
        begin = System.currentTimeMillis();

        try{ String tsql=" Isnull(z.CompanyName, '') as headquartersname,Isnull(a.CreateOperator, '') CreateOperator,Isnull(z.CompanyPhoneNumber, '') headquarterphone" +
                ",'"+databasename+"'as databasename "+
                ",Isnull(b.FyCloudCode,'') consignorCompanySende, " +
                "Isnull(c.FyCloudCode,'') consigneeCompanySenderCode," +
                "Isnull(b.Longitude,'') ConsignmentLongitude," +
                "Isnull(b.Latitude,'') ConsignmentLatitude," +
                "Isnull(c.Longitude,'') ArrivalLongitude," +
                "Isnull(c.Latitude,'') ArrivalLatitude," +
//                "CONVERT(varchar(200),a.SendLongitude) SendLongitude," +
//                "CONVERT(varchar(200),a.SendLatitude) SendLatitude," +
//                "a.PickAddress PickAddress," +
//                "CONVERT(varchar(200),a.ReceiveLongitude) ReceiveLongitude," +
//                " CONVERT(varchar(200),a.ReceiveLatitude) ReceiveLatitude," +
                "Isnull(z.FyCloudCode,'') Headquarterscode," +
                "Isnull(z.FyCloudPassword,'') headquarterspassword," +
                "Isnull(c.FyCloudCode,'') arrivalcode," +
                "Isnull(c.FyCloudPassword,'') arrivalpassword," +
                "Isnull(b.FyCloudCode ,'') consignmentcode," +
                "Isnull(b.FyCloudPassword,'') consignmentpassword,";
            List<Jrpt> jrpts = jrptService.select();
//            for (Jrpt jrpt : jrpts) {
            int i=0;
            while(true){
                i++;
                seleclSql=" select * from( select "+tsql+"Row_Number() OVER(ORDER BY a.ConsignmentBillMasterId) AS rowNum,a.OrganizationCode,Isnull(ConsignmentBillMasterId,'')ConsignmentBillMasterId,Isnull(ConsignmentBillNumber,'')ConsignmentBillNumber, \n" +
                        "       GoodsNumber,ManualNumber, ConsignmentBillDate,PlaceOfLoading" +
                        ",SendCompany,ReceiveCompany,UnloadPlace,ConsignorCompanyCode" +
                        ", ConsignorCompany, Consignor, ConsignorMobileTelephone,ConsignorTelephone" +
                        ", ConsignorAddress,ConsigneeCompanyCode,ConsigneeCompany,Consignee" +
                        ",ConsigneeMobileTelephone,ConsigneeTelephone,ConsigneeAddress,OneCardCode" +
                        ",BankName,AccountHolder,Account,PaymentMethod" +
                        ",GoodsPickupMethod,ConsignmentBillRemark,GoodsName,GoodsPack" +
                        ", IsReceipt,ReceiptNumber,ReceiptCount,ReceiptRemark" +
                        ",TotalNumberOfPackages,TotalWeight,TotalVolume,TotalTransportCost" +
                        ", CollectionGoodsValue,AdvanceGoodsValue, AdvanceTransportCost ,0 datatype,a.createTime SysTime " +
                        ", Consignoridcard,Consigneeidcard,ISNULL(b.Longitude,'0')SendLongitude" +
                        ",ISNULL(b.Latitude,'0')SendLatitude,'' PickAddress,ISNULL(c.Longitude,'0')ReceiveLongitude," +
                        "     ISNULL(c.Latitude,'0')ReceiveLatitude, " +
                        "      convert(varchar(20),convert(decimal(18,0),CASE WHEN OfflineUpload='App' THEN 1 WHEN  OfflineUpload='在线下单' THEN 2 ELSE 0 END))  CreateType,Isnull(a.PlatformNumber, '') PlatformNumber" +
                        ",ArrivalAllPayCost,InsuranceAmount,InsuranceCost,a.CreateTime,TransferCost,SendCost,PickupCost,PackCost,OtherCost " +
                        "       from ConsignmentBillMaster as a WITH(NOLOCK) " +
                        "       left join (SELECT * FROM Sys_Company WITH(NOLOCK) ) as b on  a.OrganizationCode=b.OrganizationCode and  a.SendCompany=b.CompanyName\n" +
                        "       left join (SELECT * FROM Sys_Company WITH(NOLOCK) ) as c on  a.OrganizationCode=c.OrganizationCode and a.ReceiveCompany=c.CompanyName\n" +
                        "    left join Sys_Company z WITH(NOLOCK) on a.OrganizationCode=z.OrganizationCode and z.CompanyType='总公司'"+
                        " LEFT JOIN CollectionGoodsValueAccount cva ON a.ConsignmentBillMasterId=cva.ConsignmentBillMasterId " +
                        "  LEFT JOIN BillOtherInfo ON a.ConsignmentBillMasterId=BillOtherInfoId "+
                        "       where CollectionGoodsValueDec=cva.CollectionGoodsValue and a.createTime>='"+CreateTimeBegin+"' AND a.createTime<='"+CreateTimeEnd+"' ) temp " +
                        " where rowNum BETWEEN "+((i-1)*10000+1)+"  AND "+i*10000+" " ;
                List<GoodstrackedRecordTopPublicF6> listByConsignmentBillMaster = jdbcDao.queryListForSql(seleclSql, GoodstrackedRecordTopPublicF6.class);
                if (listByConsignmentBillMaster==null||listByConsignmentBillMaster.size()==0){
                    break;
                }
                String numSql="";
                int num=0;
                int pointsDataLimit = 500;//限制条数

                Integer size = listByConsignmentBillMaster.size();
                log.info(i+"库："+databasename+"sql:"+seleclSql);
                log.info(i+"库："+databasename+"总数:"+listByConsignmentBillMaster.size());
                if(pointsDataLimit<size){
                    int part = size/pointsDataLimit;//分批数
                    ExecutorService pool = Executors.newFixedThreadPool(part+1);

                    for (int c = 0; c < part; c++) {
                        List<GoodstrackedRecordTopPublicF6> listPage = listByConsignmentBillMaster.subList(0, pointsDataLimit);
                        try{
                            //剔除
                            JSONArray a = (JSONArray) JSONObject.toJSON(listPage);
                            GoodsOrderCallable callable = new GoodsOrderCallable( "top123",a.toString());
                            Future fContent = pool.submit(callable);
                            a=null;
                            listPage=null;
                        }catch (Exception e){
                            log.error("线程异常",e);

                        }
                        listByConsignmentBillMaster.subList(0, pointsDataLimit).clear();

                    }
                    pool.shutdown();
                    if(!listByConsignmentBillMaster.isEmpty()){
                        try{
                            for (GoodstrackedRecordTopPublicF6 s : listByConsignmentBillMaster) {
                                try{
                                    String  insertSql = "insert into GoodsTracked_Record_Top_Public( " +
                                            "headquartersname,CreateOperator,CreateTime,headquarterphone,databasename,consignorCompanySende,consigneeCompanySenderCode,createType"+
                                            ",ConsignmentLongitude,ConsignmentLatitude,ArrivalLongitude,ArrivalLatitude," +
                                            "SendLongitude,SendLatitude,PickAddress,PlatformNumber,ReceiveLongitude,ReceiveLatitude," +
                                            "Headquarterscode,headquarterspassword,arrivalcode,arrivalpassword,consignmentcode ,consignmentpassword," +
                                            "  OrganizationCode,ConsignmentBillMasterId,ConsignmentBillNumber,GoodsNumber,ManualNumber,ConsignmentBillDate,PlaceOfLoading,SendCompany,ReceiveCompany,UnloadPlace,ConsignorCompanyCode,ConsignorCompany,Consignor,ConsignorMobileTelephone,ConsignorTelephone,ConsignorAddress,ConsigneeCompanyCode,ConsigneeCompany, Consignee,ConsigneeMobileTelephone" +
                                            "  ,ConsigneeTelephone, ConsigneeAddress,Consignoridcard,Consigneeidcard,OneCardCode,BankName,AccountHolder,Account,PaymentMethod,GoodsPickupMethod,ConsignmentBillRemark,GoodsName, GoodsPack,IsReceipt,ReceiptNumber,ReceiptCount,ReceiptRemark,TotalNumberOfPackages," +
                                            " TotalWeight,ArrivalAllPayCost,InsuranceAmount,InsuranceCost, TotalVolume," +
                                            "TransferCost,SendCost,PickupCost,PackCost,OtherCost,TotalTransportCost, CollectionGoodsValue,AdvanceGoodsValue,AdvanceTransportCost,DataType,SysTime) " +
                                            " values ";
                                    insertSql=insertSql+"('"+s.getHeadquartersname()+"','"+s.getCreateoperator()+"','"+s.getCreatetime()+"','"+s.getHeadquarterphone()+"','"+s.getDatabasename()+"','"+s.getConsignorcompanysende()
                                            +"','"+s.getConsigneecompanysendercode()+"','"+s.getCreatetype()+"','"+s.getConsignmentlongitude()+"','"+s.getConsignmentlatitude()+"','"+
                                            s.getArrivallongitude()+"','"+s.getArrivallatitude()+"','"+s.getSendlongitude()+"','"+s.getSendlatitude()+"','"
                                            +s.getPickaddress()+"','"+s.getPlatformnumber()+"','"+s.getReceivelongitude()+"','"+s.getReceivelatitude()+"','"+s.getHeadquarterscode()
                                            +"','"+s.getHeadquarterspassword()+"','"+s.getArrivalcode()+"','"+s.getArrivalpassword()+"','"+s.getConsignmentcode ()+"','"
                                            +s.getConsignmentpassword()+"','"+s.getOrganizationcode()+"','"+s.getConsignmentbillmasterid()+"','"+s.getConsignmentbillnumber()
                                            +"','"+s.getGoodsnumber()+"','"+s.getManualnumber()+"','"+s.getConsignmentbilldate()+"','"+s.getPlaceofloading()+"','"+s.getSendcompany()
                                            +"','"+s.getReceivecompany()+"','"+s.getUnloadplace()+"','"+s.getConsignorcompanycode()+"','"+s.getConsignorcompany()+"','"+s.getConsignor()
                                            +"','"+s.getConsignormobiletelephone()+"','"+s.getConsignortelephone()+"','"+s.getConsignoraddress()+"','"+s.getConsigneecompanycode()+"','"
                                            +s.getConsigneecompany()+"','"+s.getConsignee()+"','"+s.getConsigneemobiletelephone  ()+"','"+s.getConsigneetelephone()+"','"+s.getConsigneeaddress()+"','"+s.getConsignoridcard()+"','"+s.getConsigneeidcard()+"','"+s.getOnecardcode()+"','"+s.getBankname()+"','"+s.getAccountholder()+"','"+s.getAccount()+"','"+s.getPaymentmethod()+"','"+s.getGoodspickupmethod()+"','"+s.getConsignmentbillremark()+"','"+s.getGoodsname()+"','"+s.getGoodspack()+"','"+s.getIsreceipt()+"','"+s.getReceiptnumber()+"','"+s.getReceiptcount()+"','"+s.getReceiptremark()+"','"+s.getTotalnumberofpackages()+"','"+s.getTotalweight()+"','"+s.getArrivalallpaycost()+"','"+s.getInsuranceamount()+"','"+s.getInsurancecost()+"','"+s.getTotalvolume()+"','"+s.getTransfercost()+"','"+s.getSendcost()+"','"+s.getPickupcost()+"','"+s.getPackcost()+"','"+s.getOthercost()+"','"+s.getTotaltransportcost()+"','"+s.getCollectiongoodsvalue()+"','"+s.getAdvancegoodsvalue()+"','"
                                            +s.getAdvancetransportcost()+"','0','"+s.getSystime()+"')";
                                    insertSql=insertSql.replace("null","");
                                    jdbcDao_GoodsTracked.updateForSql(insertSql);
                                }catch (Exception e){
                                    log.error("订单1补抓 error:",e);

                                }
                            }
                        }catch (Exception e){
                            log.error("线程异常2",e);
                        }
                    }
                }else{
                    for (GoodstrackedRecordTopPublicF6 s : listByConsignmentBillMaster) {
                        try{
                            String  insertSql = "insert into GoodsTracked_Record_Top_Public( " +
                                    "headquartersname,CreateOperator,CreateTime,headquarterphone,databasename,consignorCompanySende,consigneeCompanySenderCode,createType"+
                                    ",ConsignmentLongitude,ConsignmentLatitude,ArrivalLongitude,ArrivalLatitude," +
                                    "SendLongitude,SendLatitude,PickAddress,PlatformNumber,ReceiveLongitude,ReceiveLatitude," +
                                    "Headquarterscode,headquarterspassword,arrivalcode,arrivalpassword,consignmentcode ,consignmentpassword," +
                                    "  OrganizationCode,ConsignmentBillMasterId,ConsignmentBillNumber,GoodsNumber,ManualNumber,ConsignmentBillDate,PlaceOfLoading,SendCompany,ReceiveCompany,UnloadPlace,ConsignorCompanyCode,ConsignorCompany,Consignor,ConsignorMobileTelephone,ConsignorTelephone,ConsignorAddress,ConsigneeCompanyCode,ConsigneeCompany, Consignee,ConsigneeMobileTelephone" +
                                    "  ,ConsigneeTelephone, ConsigneeAddress,Consignoridcard,Consigneeidcard,OneCardCode,BankName,AccountHolder,Account,PaymentMethod,GoodsPickupMethod,ConsignmentBillRemark,GoodsName, GoodsPack,IsReceipt,ReceiptNumber,ReceiptCount,ReceiptRemark,TotalNumberOfPackages," +
                                    " TotalWeight,ArrivalAllPayCost,InsuranceAmount,InsuranceCost, TotalVolume," +
                                    "TransferCost,SendCost,PickupCost,PackCost,OtherCost,TotalTransportCost, CollectionGoodsValue,AdvanceGoodsValue,AdvanceTransportCost,DataType,SysTime) " +
                                    " values ";
                            insertSql=insertSql+"('"+s.getHeadquartersname()+"','"+s.getCreateoperator()+"','"+s.getCreatetime()+"','"+s.getHeadquarterphone()+"','"+s.getDatabasename()+"','"+s.getConsignorcompanysende()
                                    +"','"+s.getConsigneecompanysendercode()+"','"+s.getCreatetype()+"','"+s.getConsignmentlongitude()+"','"+s.getConsignmentlatitude()+"','"+
                                    s.getArrivallongitude()+"','"+s.getArrivallatitude()+"','"+s.getSendlongitude()+"','"+s.getSendlatitude()+"','"
                                    +s.getPickaddress()+"','"+s.getPlatformnumber()+"','"+s.getReceivelongitude()+"','"+s.getReceivelatitude()+"','"+s.getHeadquarterscode()
                                    +"','"+s.getHeadquarterspassword()+"','"+s.getArrivalcode()+"','"+s.getArrivalpassword()+"','"+s.getConsignmentcode ()+"','"
                                    +s.getConsignmentpassword()+"','"+s.getOrganizationcode()+"','"+s.getConsignmentbillmasterid()+"','"+s.getConsignmentbillnumber()
                                    +"','"+s.getGoodsnumber()+"','"+s.getManualnumber()+"','"+s.getConsignmentbilldate()+"','"+s.getPlaceofloading()+"','"+s.getSendcompany()
                                    +"','"+s.getReceivecompany()+"','"+s.getUnloadplace()+"','"+s.getConsignorcompanycode()+"','"+s.getConsignorcompany()+"','"+s.getConsignor()
                                    +"','"+s.getConsignormobiletelephone()+"','"+s.getConsignortelephone()+"','"+s.getConsignoraddress()+"','"+s.getConsigneecompanycode()+"','"
                                    +s.getConsigneecompany()+"','"+s.getConsignee()+"','"+s.getConsigneemobiletelephone  ()+"','"+s.getConsigneetelephone()+"','"+s.getConsigneeaddress()+"','"+s.getConsignoridcard()+"','"+s.getConsigneeidcard()+"','"+s.getOnecardcode()+"','"+s.getBankname()+"','"+s.getAccountholder()+"','"+s.getAccount()+"','"+s.getPaymentmethod()+"','"+s.getGoodspickupmethod()+"','"+s.getConsignmentbillremark()+"','"+s.getGoodsname()+"','"+s.getGoodspack()+"','"+s.getIsreceipt()+"','"+s.getReceiptnumber()+"','"+s.getReceiptcount()+"','"+s.getReceiptremark()+"','"+s.getTotalnumberofpackages()+"','"+s.getTotalweight()+"','"+s.getArrivalallpaycost()+"','"+s.getInsuranceamount()+"','"+s.getInsurancecost()+"','"+s.getTotalvolume()+"','"+s.getTransfercost()+"','"+s.getSendcost()+"','"+s.getPickupcost()+"','"+s.getPackcost()+"','"+s.getOthercost()+"','"+s.getTotaltransportcost()+"','"+s.getCollectiongoodsvalue()+"','"+s.getAdvancegoodsvalue()+"','"
                                    +s.getAdvancetransportcost()+"','0','"+s.getSystime()+"')";
                            insertSql=insertSql.replace("null","");
                            jdbcDao_GoodsTracked.updateForSql(insertSql);
                        }catch (Exception e){
                            log.error("订单2补抓 error:",e);

                        }
                    }
                }
                end = System.currentTimeMillis();
                log.info("CreateTimeBegin:"+CreateTimeBegin+" CreateTimeEnd:"+CreateTimeEnd+" OrganizationCode:"+OrganizationCode+" DataSource:" + dataSource + ";Databasename:" + databasename + ";订单：" + listByConsignmentBillMaster.size() + ";消耗" + (end - begin) + "豪秒。");
                listByConsignmentBillMaster=null;

            }
//            }
        }catch (Exception e){
            log.error(" order error:",e);
        }
    }

    static class GoodsOrderCallable implements Callable<Object> {
        //        private List<GoodsPublic> goods;
        private String type="";
        private String data="";

        GoodsOrderCallable(String type,String data) {
            this.type = type;
            this.data=data;
        }

        public Object call() throws Exception {
            String result="";
            try{
                JSONArray json = JSONObject.parseArray(this.data);
                    List<GoodstrackedRecordTopPublicF6> subs= JSONArray.parseArray(json.toJSONString(),GoodstrackedRecordTopPublicF6.class);
                    if(subs!=null){
                        for (GoodstrackedRecordTopPublicF6 s : subs) {
                            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

                            try{
                                String ConsignmentBillDate="";
                                if (s.getConsignmentbilldate()!=null){
                                    ConsignmentBillDate= sdf.format(s.getConsignmentbilldate());
                                }
                                String systime="";
                                if (s.getSystime()!=null){
                                    systime= sdf.format(s.getSystime());
                                }
                                String CreateTime="";
                                if (s.getCreatetime()!=null){
                                    CreateTime= sdf.format(s.getCreatetime());
                                }
                                String  insertSql = "insert into GoodsTracked_Record_Top_Public( " +
                                        "headquartersname,CreateOperator,CreateTime,headquarterphone,databasename,consignorCompanySende,consigneeCompanySenderCode,createType"+
                                        ",ConsignmentLongitude,ConsignmentLatitude,ArrivalLongitude,ArrivalLatitude," +
                                        "SendLongitude,SendLatitude,PickAddress,PlatformNumber,ReceiveLongitude,ReceiveLatitude," +
                                        "Headquarterscode,headquarterspassword,arrivalcode,arrivalpassword,consignmentcode ,consignmentpassword," +
                                        "  OrganizationCode,ConsignmentBillMasterId,ConsignmentBillNumber,GoodsNumber,ManualNumber,ConsignmentBillDate,PlaceOfLoading,SendCompany,ReceiveCompany,UnloadPlace,ConsignorCompanyCode,ConsignorCompany,Consignor,ConsignorMobileTelephone,ConsignorTelephone,ConsignorAddress,ConsigneeCompanyCode,ConsigneeCompany, Consignee,ConsigneeMobileTelephone" +
                                        "  ,ConsigneeTelephone, ConsigneeAddress,Consignoridcard,Consigneeidcard,OneCardCode,BankName,AccountHolder,Account,PaymentMethod,GoodsPickupMethod,ConsignmentBillRemark,GoodsName, GoodsPack,IsReceipt,ReceiptNumber,ReceiptCount,ReceiptRemark,TotalNumberOfPackages," +
                                        " TotalWeight,ArrivalAllPayCost,InsuranceAmount,InsuranceCost, TotalVolume," +
                                        "TransferCost,SendCost,PickupCost,PackCost,OtherCost,TotalTransportCost, CollectionGoodsValue,AdvanceGoodsValue,AdvanceTransportCost,DataType,SysTime) " +
                                        " values ";
                                insertSql=insertSql+"('"+s.getHeadquartersname()+"','"+s.getCreateoperator()+"','"+CreateTime+"','"+s.getHeadquarterphone()+"','"+s.getDatabasename()+"','"+s.getConsignorcompanysende()
                                        +"','"+s.getConsigneecompanysendercode()+"','"+s.getCreatetype()+"','"+s.getConsignmentlongitude()+"','"+s.getConsignmentlatitude()+"','"+
                                        s.getArrivallongitude()+"','"+s.getArrivallatitude()+"','"+s.getSendlongitude()+"','"+s.getSendlatitude()+"','"
                                        +s.getPickaddress()+"','"+s.getPlatformnumber()+"','"+s.getReceivelongitude()+"','"+s.getReceivelatitude()+"','"+s.getHeadquarterscode()
                                        +"','"+s.getHeadquarterspassword()+"','"+s.getArrivalcode()+"','"+s.getArrivalpassword()+"','"+s.getConsignmentcode ()+"','"
                                        +s.getConsignmentpassword()+"','"+s.getOrganizationcode()+"','"+s.getConsignmentbillmasterid()+"','"+s.getConsignmentbillnumber()
                                        +"','"+s.getGoodsnumber()+"','"+s.getManualnumber()+"','"
                                        + ConsignmentBillDate
                                        +"','"+s.getPlaceofloading()+"','"+s.getSendcompany()
                                        +"','"+s.getReceivecompany()+"','"+s.getUnloadplace()+"','"+s.getConsignorcompanycode()+"','"+s.getConsignorcompany()+"','"+s.getConsignor()
                                        +"','"+s.getConsignormobiletelephone()+"','"+s.getConsignortelephone()+"','"+s.getConsignoraddress()+"','"+s.getConsigneecompanycode()+"','"
                                        +s.getConsigneecompany()+"','"+s.getConsignee()+"','"+s.getConsigneemobiletelephone  ()+"','"+s.getConsigneetelephone()+"','"+s.getConsigneeaddress()+"','"+s.getConsignoridcard()+"','"+s.getConsigneeidcard()+"','"+s.getOnecardcode()+"','"+s.getBankname()+"','"+s.getAccountholder()+"','"+s.getAccount()+"','"+s.getPaymentmethod()+"','"+s.getGoodspickupmethod()+"','"+s.getConsignmentbillremark()+"','"+s.getGoodsname()+"','"+s.getGoodspack()+"','"+s.getIsreceipt()+"','"+s.getReceiptnumber()+"','"+s.getReceiptcount()+"','"+s.getReceiptremark()+"','"+s.getTotalnumberofpackages()+"','"+s.getTotalweight()+"','"+s.getArrivalallpaycost()+"','"+s.getInsuranceamount()+"','"+s.getInsurancecost()+"','"+s.getTotalvolume()+"','"+s.getTransfercost()+"','"+s.getSendcost()+"','"+s.getPickupcost()+"','"+s.getPackcost()+"','"+s.getOthercost()+"','"+s.getTotaltransportcost()+"','"+s.getCollectiongoodsvalue()+"','"+s.getAdvancegoodsvalue()+"','"
                                        +s.getAdvancetransportcost()+"','0','"+systime+"')";
                                insertSql=insertSql.replace("null","");
//                                log.info("lmlsave:"+s.getConsignmentbillmasterid());
                                OrderUtil.insert(insertSql);
                            }catch (Exception e){
                                log.error("订单多线程 error:",e);
                            }
                        }
                    }
                    subs=null;
                json=null;
            }catch (Exception e){
                log.error("call error",e);
            }
            return result;
        }
    }
}
